initial commit
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
using Indotalent.Infrastructure.Database;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Indotalent.Features.Inventory.Scrapping.Cqrs;
|
||||
|
||||
public class UpdateScrappingItemRequest
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? ProductId { get; set; }
|
||||
public double? Movement { get; set; }
|
||||
}
|
||||
|
||||
public record UpdateScrappingItemCommand(UpdateScrappingItemRequest Data) : IRequest<bool>;
|
||||
|
||||
public class UpdateScrappingItemHandler : IRequestHandler<UpdateScrappingItemCommand, bool>
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
public UpdateScrappingItemHandler(AppDbContext context) => _context = context;
|
||||
|
||||
public async Task<bool> Handle(UpdateScrappingItemCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = await _context.InventoryTransaction
|
||||
.FirstOrDefaultAsync(x => x.Id == request.Data.Id, cancellationToken);
|
||||
|
||||
if (entity == null) return false;
|
||||
|
||||
entity.ProductId = request.Data.ProductId;
|
||||
entity.Movement = Math.Abs(request.Data.Movement ?? 0);
|
||||
|
||||
_context.CalculateInvenTrans(entity);
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user