initial commit
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
using Application.Common.Extensions;
|
||||
using Application.Common.Repositories;
|
||||
using Application.Features.InventoryTransactionManager;
|
||||
using Application.Features.NumberSequenceManager;
|
||||
using Domain.Entities;
|
||||
using Domain.Enums;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Application.Features.TransferInManager.Commands;
|
||||
|
||||
public class CreateTransferInResult
|
||||
{
|
||||
public TransferIn? Data { get; set; }
|
||||
}
|
||||
|
||||
public class CreateTransferInRequest : IRequest<CreateTransferInResult>
|
||||
{
|
||||
public DateTime? TransferReceiveDate { get; init; }
|
||||
public string? Status { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public string? TransferOutId { get; init; }
|
||||
public string? CreatedById { get; init; }
|
||||
}
|
||||
|
||||
public class CreateTransferInValidator : AbstractValidator<CreateTransferInRequest>
|
||||
{
|
||||
public CreateTransferInValidator()
|
||||
{
|
||||
RuleFor(x => x.TransferReceiveDate).NotEmpty();
|
||||
RuleFor(x => x.Status).NotEmpty();
|
||||
RuleFor(x => x.TransferOutId).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class CreateTransferInHandler : IRequestHandler<CreateTransferInRequest, CreateTransferInResult>
|
||||
{
|
||||
private readonly ICommandRepository<TransferIn> _deliveryOrderRepository;
|
||||
private readonly ICommandRepository<InventoryTransaction> _itemRepository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly NumberSequenceService _numberSequenceService;
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public CreateTransferInHandler(
|
||||
ICommandRepository<TransferIn> deliveryOrderRepository,
|
||||
ICommandRepository<InventoryTransaction> itemRepository,
|
||||
IUnitOfWork unitOfWork,
|
||||
NumberSequenceService numberSequenceService,
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_deliveryOrderRepository = deliveryOrderRepository;
|
||||
_itemRepository = itemRepository;
|
||||
_unitOfWork = unitOfWork;
|
||||
_numberSequenceService = numberSequenceService;
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<CreateTransferInResult> Handle(CreateTransferInRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = new TransferIn();
|
||||
entity.CreatedById = request.CreatedById;
|
||||
|
||||
entity.Number = _numberSequenceService.GenerateNumber(nameof(TransferIn), "", "IN");
|
||||
entity.TransferReceiveDate = request.TransferReceiveDate;
|
||||
entity.Status = (TransferStatus)int.Parse(request.Status!);
|
||||
entity.Description = request.Description;
|
||||
entity.TransferOutId = request.TransferOutId;
|
||||
|
||||
await _deliveryOrderRepository.CreateAsync(entity, cancellationToken);
|
||||
await _unitOfWork.SaveAsync(cancellationToken);
|
||||
|
||||
var items = await _itemRepository
|
||||
.GetQuery()
|
||||
.ApplyIsDeletedFilter(false)
|
||||
.Where(x => x.ModuleId == entity.TransferOutId && x.ModuleName == nameof(TransferOut))
|
||||
.Include(x => x.Product)
|
||||
.ToListAsync(cancellationToken);
|
||||
|
||||
foreach (var item in items)
|
||||
{
|
||||
if (item?.Product?.Physical ?? false)
|
||||
{
|
||||
await _inventoryTransactionService.TransferInCreateInvenTrans(
|
||||
entity.Id,
|
||||
item.ProductId,
|
||||
item.Movement,
|
||||
entity.CreatedById,
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return new CreateTransferInResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
using Application.Common.Repositories;
|
||||
using Application.Features.InventoryTransactionManager;
|
||||
using Domain.Entities;
|
||||
using Domain.Enums;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.TransferInManager.Commands;
|
||||
|
||||
public class DeleteTransferInResult
|
||||
{
|
||||
public TransferIn? Data { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteTransferInRequest : IRequest<DeleteTransferInResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? DeletedById { get; init; }
|
||||
}
|
||||
|
||||
public class DeleteTransferInValidator : AbstractValidator<DeleteTransferInRequest>
|
||||
{
|
||||
public DeleteTransferInValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class DeleteTransferInHandler : IRequestHandler<DeleteTransferInRequest, DeleteTransferInResult>
|
||||
{
|
||||
private readonly ICommandRepository<TransferIn> _repository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public DeleteTransferInHandler(
|
||||
ICommandRepository<TransferIn> repository,
|
||||
IUnitOfWork unitOfWork,
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_repository = repository;
|
||||
_unitOfWork = unitOfWork;
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<DeleteTransferInResult> Handle(DeleteTransferInRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
var entity = await _repository.GetAsync(request.Id ?? string.Empty, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
throw new Exception($"Entity not found: {request.Id}");
|
||||
}
|
||||
|
||||
entity.UpdatedById = request.DeletedById;
|
||||
|
||||
_repository.Delete(entity);
|
||||
await _unitOfWork.SaveAsync(cancellationToken);
|
||||
|
||||
await _inventoryTransactionService.PropagateParentUpdate(
|
||||
entity.Id,
|
||||
nameof(TransferIn),
|
||||
entity.TransferReceiveDate,
|
||||
(InventoryTransactionStatus?)entity.Status,
|
||||
entity.IsDeleted,
|
||||
entity.UpdatedById,
|
||||
null,
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
return new DeleteTransferInResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
using Application.Common.Repositories;
|
||||
using Application.Features.InventoryTransactionManager;
|
||||
using Domain.Entities;
|
||||
using Domain.Enums;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.TransferInManager.Commands;
|
||||
|
||||
public class UpdateTransferInResult
|
||||
{
|
||||
public TransferIn? Data { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateTransferInRequest : IRequest<UpdateTransferInResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public DateTime? TransferReceiveDate { get; init; }
|
||||
public string? Status { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public string? TransferOutId { get; init; }
|
||||
public string? UpdatedById { get; init; }
|
||||
}
|
||||
|
||||
public class UpdateTransferInValidator : AbstractValidator<UpdateTransferInRequest>
|
||||
{
|
||||
public UpdateTransferInValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
RuleFor(x => x.TransferReceiveDate).NotEmpty();
|
||||
RuleFor(x => x.Status).NotEmpty();
|
||||
RuleFor(x => x.TransferOutId).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class UpdateTransferInHandler : IRequestHandler<UpdateTransferInRequest, UpdateTransferInResult>
|
||||
{
|
||||
private readonly ICommandRepository<TransferIn> _repository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
private readonly ICommandRepository<TransferOut> _transferOutRepository;
|
||||
|
||||
public UpdateTransferInHandler(
|
||||
ICommandRepository<TransferIn> repository,
|
||||
IUnitOfWork unitOfWork,
|
||||
InventoryTransactionService inventoryTransactionService,
|
||||
ICommandRepository<TransferOut> transferOutRepository
|
||||
)
|
||||
{
|
||||
_repository = repository;
|
||||
_unitOfWork = unitOfWork;
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
_transferOutRepository = transferOutRepository;
|
||||
}
|
||||
|
||||
public async Task<UpdateTransferInResult> Handle(UpdateTransferInRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
|
||||
var entity = await _repository.GetAsync(request.Id ?? string.Empty, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
throw new Exception($"Entity not found: {request.Id}");
|
||||
}
|
||||
|
||||
entity.UpdatedById = request.UpdatedById;
|
||||
|
||||
entity.TransferReceiveDate = request.TransferReceiveDate;
|
||||
entity.Status = (TransferStatus)int.Parse(request.Status!);
|
||||
entity.Description = request.Description;
|
||||
entity.TransferOutId = request.TransferOutId;
|
||||
|
||||
_repository.Update(entity);
|
||||
await _unitOfWork.SaveAsync(cancellationToken);
|
||||
|
||||
var transferOut = await _transferOutRepository.GetAsync(entity.TransferOutId ?? string.Empty, cancellationToken);
|
||||
|
||||
await _inventoryTransactionService.PropagateParentUpdate(
|
||||
entity.Id,
|
||||
nameof(TransferIn),
|
||||
entity.TransferReceiveDate,
|
||||
(InventoryTransactionStatus?)entity.Status,
|
||||
entity.IsDeleted,
|
||||
entity.UpdatedById,
|
||||
transferOut?.WarehouseToId,
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
return new UpdateTransferInResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user