initial commit
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
using Application.Common.Repositories;
|
||||
using Application.Features.NumberSequenceManager;
|
||||
using Domain.Entities;
|
||||
using Domain.Enums;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.TransferOutManager.Commands;
|
||||
|
||||
public class CreateTransferOutResult
|
||||
{
|
||||
public TransferOut? Data { get; set; }
|
||||
}
|
||||
|
||||
public class CreateTransferOutRequest : IRequest<CreateTransferOutResult>
|
||||
{
|
||||
public DateTime? TransferReleaseDate { get; init; }
|
||||
public string? Status { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public string? WarehouseFromId { get; init; }
|
||||
public string? WarehouseToId { get; init; }
|
||||
public string? CreatedById { get; init; }
|
||||
}
|
||||
|
||||
public class CreateTransferOutValidator : AbstractValidator<CreateTransferOutRequest>
|
||||
{
|
||||
public CreateTransferOutValidator()
|
||||
{
|
||||
RuleFor(x => x.TransferReleaseDate).NotEmpty();
|
||||
RuleFor(x => x.Status).NotEmpty();
|
||||
RuleFor(x => x.WarehouseFromId).NotEmpty();
|
||||
RuleFor(x => x.WarehouseToId).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class CreateTransferOutHandler : IRequestHandler<CreateTransferOutRequest, CreateTransferOutResult>
|
||||
{
|
||||
private readonly ICommandRepository<TransferOut> _repository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly NumberSequenceService _numberSequenceService;
|
||||
|
||||
public CreateTransferOutHandler(
|
||||
ICommandRepository<TransferOut> repository,
|
||||
IUnitOfWork unitOfWork,
|
||||
NumberSequenceService numberSequenceService
|
||||
)
|
||||
{
|
||||
_repository = repository;
|
||||
_unitOfWork = unitOfWork;
|
||||
_numberSequenceService = numberSequenceService;
|
||||
}
|
||||
|
||||
public async Task<CreateTransferOutResult> Handle(CreateTransferOutRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = new TransferOut();
|
||||
entity.CreatedById = request.CreatedById;
|
||||
|
||||
entity.Number = _numberSequenceService.GenerateNumber(nameof(TransferOut), "", "OUT");
|
||||
entity.TransferReleaseDate = request.TransferReleaseDate;
|
||||
entity.Status = (TransferStatus)int.Parse(request.Status!);
|
||||
entity.Description = request.Description;
|
||||
entity.WarehouseFromId = request.WarehouseFromId;
|
||||
entity.WarehouseToId = request.WarehouseToId;
|
||||
|
||||
await _repository.CreateAsync(entity, cancellationToken);
|
||||
await _unitOfWork.SaveAsync(cancellationToken);
|
||||
|
||||
return new CreateTransferOutResult
|
||||
{
|
||||
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.TransferOutManager.Commands;
|
||||
|
||||
public class DeleteTransferOutResult
|
||||
{
|
||||
public TransferOut? Data { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteTransferOutRequest : IRequest<DeleteTransferOutResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? DeletedById { get; init; }
|
||||
}
|
||||
|
||||
public class DeleteTransferOutValidator : AbstractValidator<DeleteTransferOutRequest>
|
||||
{
|
||||
public DeleteTransferOutValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class DeleteTransferOutHandler : IRequestHandler<DeleteTransferOutRequest, DeleteTransferOutResult>
|
||||
{
|
||||
private readonly ICommandRepository<TransferOut> _repository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public DeleteTransferOutHandler(
|
||||
ICommandRepository<TransferOut> repository,
|
||||
IUnitOfWork unitOfWork,
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_repository = repository;
|
||||
_unitOfWork = unitOfWork;
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<DeleteTransferOutResult> Handle(DeleteTransferOutRequest 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(TransferOut),
|
||||
entity.TransferReleaseDate,
|
||||
(InventoryTransactionStatus?)entity.Status,
|
||||
entity.IsDeleted,
|
||||
entity.UpdatedById,
|
||||
null,
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
return new DeleteTransferOutResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
using Application.Common.Repositories;
|
||||
using Application.Features.InventoryTransactionManager;
|
||||
using Domain.Entities;
|
||||
using Domain.Enums;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.TransferOutManager.Commands;
|
||||
|
||||
public class UpdateTransferOutResult
|
||||
{
|
||||
public TransferOut? Data { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateTransferOutRequest : IRequest<UpdateTransferOutResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public DateTime? TransferReleaseDate { get; init; }
|
||||
public string? Status { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public string? WarehouseFromId { get; init; }
|
||||
public string? WarehouseToId { get; init; }
|
||||
public string? UpdatedById { get; init; }
|
||||
}
|
||||
|
||||
public class UpdateTransferOutValidator : AbstractValidator<UpdateTransferOutRequest>
|
||||
{
|
||||
public UpdateTransferOutValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
RuleFor(x => x.TransferReleaseDate).NotEmpty();
|
||||
RuleFor(x => x.Status).NotEmpty();
|
||||
RuleFor(x => x.WarehouseFromId).NotEmpty();
|
||||
RuleFor(x => x.WarehouseToId).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class UpdateTransferOutHandler : IRequestHandler<UpdateTransferOutRequest, UpdateTransferOutResult>
|
||||
{
|
||||
private readonly ICommandRepository<TransferOut> _repository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public UpdateTransferOutHandler(
|
||||
ICommandRepository<TransferOut> repository,
|
||||
IUnitOfWork unitOfWork,
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_repository = repository;
|
||||
_unitOfWork = unitOfWork;
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<UpdateTransferOutResult> Handle(UpdateTransferOutRequest 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.TransferReleaseDate = request.TransferReleaseDate;
|
||||
entity.Status = (TransferStatus)int.Parse(request.Status!);
|
||||
entity.Description = request.Description;
|
||||
entity.WarehouseFromId = request.WarehouseFromId;
|
||||
entity.WarehouseToId = request.WarehouseToId;
|
||||
|
||||
_repository.Update(entity);
|
||||
await _unitOfWork.SaveAsync(cancellationToken);
|
||||
|
||||
await _inventoryTransactionService.PropagateParentUpdate(
|
||||
entity.Id,
|
||||
nameof(TransferOut),
|
||||
entity.TransferReleaseDate,
|
||||
(InventoryTransactionStatus?)entity.Status,
|
||||
entity.IsDeleted,
|
||||
entity.UpdatedById,
|
||||
entity.WarehouseFromId,
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
return new UpdateTransferOutResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
using Application.Common.CQS.Queries;
|
||||
using Application.Common.Extensions;
|
||||
using AutoMapper;
|
||||
using Domain.Entities;
|
||||
using Domain.Enums;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Application.Features.TransferOutManager.Queries;
|
||||
|
||||
public record GetTransferOutListDto
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Number { get; init; }
|
||||
public DateTime? TransferReleaseDate { get; init; }
|
||||
public TransferStatus? Status { get; init; }
|
||||
public string? StatusName { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public string? WarehouseFromId { get; init; }
|
||||
public string? WarehouseFromName { get; init; }
|
||||
public string? WarehouseToId { get; init; }
|
||||
public string? WarehouseToName { get; init; }
|
||||
public DateTime? CreatedAtUtc { get; init; }
|
||||
}
|
||||
|
||||
public class GetTransferOutListProfile : Profile
|
||||
{
|
||||
public GetTransferOutListProfile()
|
||||
{
|
||||
CreateMap<TransferOut, GetTransferOutListDto>()
|
||||
.ForMember(
|
||||
dest => dest.WarehouseFromName,
|
||||
opt => opt.MapFrom(src => src.WarehouseFrom != null ? src.WarehouseFrom.Name : string.Empty)
|
||||
)
|
||||
.ForMember(
|
||||
dest => dest.WarehouseToName,
|
||||
opt => opt.MapFrom(src => src.WarehouseTo != null ? src.WarehouseTo.Name : string.Empty)
|
||||
)
|
||||
.ForMember(
|
||||
dest => dest.StatusName,
|
||||
opt => opt.MapFrom(src => src.Status.HasValue ? src.Status.Value.ToFriendlyName() : string.Empty)
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class GetTransferOutListResult
|
||||
{
|
||||
public List<GetTransferOutListDto>? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetTransferOutListRequest : IRequest<GetTransferOutListResult>
|
||||
{
|
||||
public bool IsDeleted { get; init; } = false;
|
||||
}
|
||||
|
||||
|
||||
public class GetTransferOutListHandler : IRequestHandler<GetTransferOutListRequest, GetTransferOutListResult>
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetTransferOutListHandler(IMapper mapper, IQueryContext context)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetTransferOutListResult> Handle(GetTransferOutListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = _context
|
||||
.TransferOut
|
||||
.AsNoTracking()
|
||||
.ApplyIsDeletedFilter(request.IsDeleted)
|
||||
.Include(x => x.WarehouseFrom)
|
||||
.Include(x => x.WarehouseTo)
|
||||
.AsQueryable();
|
||||
|
||||
var entities = await query.ToListAsync(cancellationToken);
|
||||
|
||||
var dtos = _mapper.Map<List<GetTransferOutListDto>>(entities);
|
||||
|
||||
return new GetTransferOutListResult
|
||||
{
|
||||
Data = dtos
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
using Application.Common.CQS.Queries;
|
||||
using Application.Common.Extensions;
|
||||
using AutoMapper;
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Application.Features.TransferOutManager.Queries;
|
||||
|
||||
|
||||
public class GetTransferOutSingleProfile : Profile
|
||||
{
|
||||
public GetTransferOutSingleProfile()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class GetTransferOutSingleResult
|
||||
{
|
||||
public TransferOut? Data { get; init; }
|
||||
public List<InventoryTransaction>? TransactionList { get; init; }
|
||||
}
|
||||
|
||||
public class GetTransferOutSingleRequest : IRequest<GetTransferOutSingleResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
}
|
||||
|
||||
public class GetTransferOutSingleValidator : AbstractValidator<GetTransferOutSingleRequest>
|
||||
{
|
||||
public GetTransferOutSingleValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class GetTransferOutSingleHandler : IRequestHandler<GetTransferOutSingleRequest, GetTransferOutSingleResult>
|
||||
{
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetTransferOutSingleHandler(
|
||||
IQueryContext context
|
||||
)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetTransferOutSingleResult> Handle(GetTransferOutSingleRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var queryData = _context
|
||||
.TransferOut
|
||||
.AsNoTracking()
|
||||
.Include(x => x.WarehouseFrom)
|
||||
.Include(x => x.WarehouseTo)
|
||||
.Where(x => x.Id == request.Id)
|
||||
.AsQueryable();
|
||||
|
||||
var data = await queryData.SingleOrDefaultAsync(cancellationToken);
|
||||
|
||||
|
||||
var queryTransactionList = _context
|
||||
.InventoryTransaction
|
||||
.AsNoTracking()
|
||||
.ApplyIsDeletedFilter(false)
|
||||
.Include(x => x.Product)
|
||||
.Include(x => x.Warehouse)
|
||||
.Include(x => x.WarehouseFrom)
|
||||
.Include(x => x.WarehouseTo)
|
||||
.Where(x => x.ModuleId == request.Id && x.ModuleName == nameof(TransferOut))
|
||||
.AsQueryable();
|
||||
|
||||
var transactionList = await queryTransactionList.ToListAsync(cancellationToken);
|
||||
|
||||
return new GetTransferOutSingleResult
|
||||
{
|
||||
Data = data,
|
||||
TransactionList = transactionList
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
using Application.Common.Extensions;
|
||||
using AutoMapper;
|
||||
using Domain.Enums;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.TransferOutManager.Queries;
|
||||
|
||||
public record GetTransferOutStatusListDto
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Name { get; init; }
|
||||
}
|
||||
|
||||
public class GetTransferOutStatusListProfile : Profile
|
||||
{
|
||||
public GetTransferOutStatusListProfile()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class GetTransferOutStatusListResult
|
||||
{
|
||||
public List<GetTransferOutStatusListDto>? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetTransferOutStatusListRequest : IRequest<GetTransferOutStatusListResult>
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public class GetTransferOutStatusListHandler : IRequestHandler<GetTransferOutStatusListRequest, GetTransferOutStatusListResult>
|
||||
{
|
||||
|
||||
public GetTransferOutStatusListHandler()
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<GetTransferOutStatusListResult> Handle(GetTransferOutStatusListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var statuses = Enum.GetValues(typeof(TransferStatus))
|
||||
.Cast<TransferStatus>()
|
||||
.Select(status => new GetTransferOutStatusListDto
|
||||
{
|
||||
Id = ((int)status).ToString(),
|
||||
Name = status.ToFriendlyName()
|
||||
})
|
||||
.ToList();
|
||||
|
||||
await Task.CompletedTask;
|
||||
|
||||
return new GetTransferOutStatusListResult
|
||||
{
|
||||
Data = statuses
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user