initial commit
This commit is contained in:
+67
@@ -0,0 +1,67 @@
|
||||
using Application.Common.Repositories;
|
||||
using Application.Features.NumberSequenceManager;
|
||||
using Domain.Entities;
|
||||
using Domain.Enums;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.PositiveAdjustmentManager.Commands;
|
||||
|
||||
public class CreatePositiveAdjustmentResult
|
||||
{
|
||||
public PositiveAdjustment? Data { get; set; }
|
||||
}
|
||||
|
||||
public class CreatePositiveAdjustmentRequest : IRequest<CreatePositiveAdjustmentResult>
|
||||
{
|
||||
public DateTime? AdjustmentDate { get; init; }
|
||||
public string? Status { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public string? CreatedById { get; init; }
|
||||
}
|
||||
|
||||
public class CreatePositiveAdjustmentValidator : AbstractValidator<CreatePositiveAdjustmentRequest>
|
||||
{
|
||||
public CreatePositiveAdjustmentValidator()
|
||||
{
|
||||
RuleFor(x => x.AdjustmentDate).NotEmpty();
|
||||
RuleFor(x => x.Status).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class CreatePositiveAdjustmentHandler : IRequestHandler<CreatePositiveAdjustmentRequest, CreatePositiveAdjustmentResult>
|
||||
{
|
||||
private readonly ICommandRepository<PositiveAdjustment> _repository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly NumberSequenceService _numberSequenceService;
|
||||
|
||||
public CreatePositiveAdjustmentHandler(
|
||||
ICommandRepository<PositiveAdjustment> repository,
|
||||
IUnitOfWork unitOfWork,
|
||||
NumberSequenceService numberSequenceService
|
||||
)
|
||||
{
|
||||
_repository = repository;
|
||||
_unitOfWork = unitOfWork;
|
||||
_numberSequenceService = numberSequenceService;
|
||||
}
|
||||
|
||||
public async Task<CreatePositiveAdjustmentResult> Handle(CreatePositiveAdjustmentRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = new PositiveAdjustment();
|
||||
entity.CreatedById = request.CreatedById;
|
||||
|
||||
entity.Number = _numberSequenceService.GenerateNumber(nameof(PositiveAdjustment), "", "ADJ+");
|
||||
entity.AdjustmentDate = request.AdjustmentDate;
|
||||
entity.Status = (AdjustmentStatus)int.Parse(request.Status!);
|
||||
entity.Description = request.Description;
|
||||
|
||||
await _repository.CreateAsync(entity, cancellationToken);
|
||||
await _unitOfWork.SaveAsync(cancellationToken);
|
||||
|
||||
return new CreatePositiveAdjustmentResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
+78
@@ -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.PositiveAdjustmentManager.Commands;
|
||||
|
||||
public class DeletePositiveAdjustmentResult
|
||||
{
|
||||
public PositiveAdjustment? Data { get; set; }
|
||||
}
|
||||
|
||||
public class DeletePositiveAdjustmentRequest : IRequest<DeletePositiveAdjustmentResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? DeletedById { get; init; }
|
||||
}
|
||||
|
||||
public class DeletePositiveAdjustmentValidator : AbstractValidator<DeletePositiveAdjustmentRequest>
|
||||
{
|
||||
public DeletePositiveAdjustmentValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class DeletePositiveAdjustmentHandler : IRequestHandler<DeletePositiveAdjustmentRequest, DeletePositiveAdjustmentResult>
|
||||
{
|
||||
private readonly ICommandRepository<PositiveAdjustment> _repository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public DeletePositiveAdjustmentHandler(
|
||||
ICommandRepository<PositiveAdjustment> repository,
|
||||
IUnitOfWork unitOfWork,
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_repository = repository;
|
||||
_unitOfWork = unitOfWork;
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<DeletePositiveAdjustmentResult> Handle(DeletePositiveAdjustmentRequest 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(PositiveAdjustment),
|
||||
entity.AdjustmentDate,
|
||||
(InventoryTransactionStatus?)entity.Status,
|
||||
entity.IsDeleted,
|
||||
entity.UpdatedById,
|
||||
null,
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
return new DeletePositiveAdjustmentResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
using Application.Common.Repositories;
|
||||
using Application.Features.InventoryTransactionManager;
|
||||
using Domain.Entities;
|
||||
using Domain.Enums;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.PositiveAdjustmentManager.Commands;
|
||||
|
||||
public class UpdatePositiveAdjustmentResult
|
||||
{
|
||||
public PositiveAdjustment? Data { get; set; }
|
||||
}
|
||||
|
||||
public class UpdatePositiveAdjustmentRequest : IRequest<UpdatePositiveAdjustmentResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public DateTime? AdjustmentDate { get; init; }
|
||||
public string? Status { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public string? UpdatedById { get; init; }
|
||||
}
|
||||
|
||||
public class UpdatePositiveAdjustmentValidator : AbstractValidator<UpdatePositiveAdjustmentRequest>
|
||||
{
|
||||
public UpdatePositiveAdjustmentValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
RuleFor(x => x.AdjustmentDate).NotEmpty();
|
||||
RuleFor(x => x.Status).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class UpdatePositiveAdjustmentHandler : IRequestHandler<UpdatePositiveAdjustmentRequest, UpdatePositiveAdjustmentResult>
|
||||
{
|
||||
private readonly ICommandRepository<PositiveAdjustment> _repository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public UpdatePositiveAdjustmentHandler(
|
||||
ICommandRepository<PositiveAdjustment> repository,
|
||||
IUnitOfWork unitOfWork,
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_repository = repository;
|
||||
_unitOfWork = unitOfWork;
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<UpdatePositiveAdjustmentResult> Handle(UpdatePositiveAdjustmentRequest 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.AdjustmentDate = request.AdjustmentDate;
|
||||
entity.Status = (AdjustmentStatus)int.Parse(request.Status!);
|
||||
entity.Description = request.Description;
|
||||
|
||||
_repository.Update(entity);
|
||||
await _unitOfWork.SaveAsync(cancellationToken);
|
||||
|
||||
await _inventoryTransactionService.PropagateParentUpdate(
|
||||
entity.Id,
|
||||
nameof(PositiveAdjustment),
|
||||
entity.AdjustmentDate,
|
||||
(InventoryTransactionStatus?)entity.Status,
|
||||
entity.IsDeleted,
|
||||
entity.UpdatedById,
|
||||
null,
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
return new UpdatePositiveAdjustmentResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
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.PositiveAdjustmentManager.Queries;
|
||||
|
||||
public record GetPositiveAdjustmentListDto
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Number { get; init; }
|
||||
public DateTime? AdjustmentDate { get; init; }
|
||||
public AdjustmentStatus? Status { get; init; }
|
||||
public string? StatusName { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public DateTime? CreatedAtUtc { get; init; }
|
||||
}
|
||||
|
||||
public class GetPositiveAdjustmentListProfile : Profile
|
||||
{
|
||||
public GetPositiveAdjustmentListProfile()
|
||||
{
|
||||
CreateMap<PositiveAdjustment, GetPositiveAdjustmentListDto>()
|
||||
.ForMember(
|
||||
dest => dest.StatusName,
|
||||
opt => opt.MapFrom(src => src.Status.HasValue ? src.Status.Value.ToFriendlyName() : string.Empty)
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class GetPositiveAdjustmentListResult
|
||||
{
|
||||
public List<GetPositiveAdjustmentListDto>? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetPositiveAdjustmentListRequest : IRequest<GetPositiveAdjustmentListResult>
|
||||
{
|
||||
public bool IsDeleted { get; init; } = false;
|
||||
}
|
||||
|
||||
|
||||
public class GetPositiveAdjustmentListHandler : IRequestHandler<GetPositiveAdjustmentListRequest, GetPositiveAdjustmentListResult>
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetPositiveAdjustmentListHandler(IMapper mapper, IQueryContext context)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetPositiveAdjustmentListResult> Handle(GetPositiveAdjustmentListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = _context
|
||||
.PositiveAdjustment
|
||||
.AsNoTracking()
|
||||
.ApplyIsDeletedFilter(request.IsDeleted)
|
||||
.AsQueryable();
|
||||
|
||||
var entities = await query.ToListAsync(cancellationToken);
|
||||
|
||||
var dtos = _mapper.Map<List<GetPositiveAdjustmentListDto>>(entities);
|
||||
|
||||
return new GetPositiveAdjustmentListResult
|
||||
{
|
||||
Data = dtos
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
using Application.Common.CQS.Queries;
|
||||
using Application.Common.Extensions;
|
||||
using AutoMapper;
|
||||
using Domain.Entities;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Application.Features.PositiveAdjustmentManager.Queries;
|
||||
|
||||
|
||||
public class GetPositiveAdjustmentSingleProfile : Profile
|
||||
{
|
||||
public GetPositiveAdjustmentSingleProfile()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class GetPositiveAdjustmentSingleResult
|
||||
{
|
||||
public PositiveAdjustment? Data { get; init; }
|
||||
public List<InventoryTransaction>? TransactionList { get; init; }
|
||||
}
|
||||
|
||||
public class GetPositiveAdjustmentSingleRequest : IRequest<GetPositiveAdjustmentSingleResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
}
|
||||
|
||||
public class GetPositiveAdjustmentSingleValidator : AbstractValidator<GetPositiveAdjustmentSingleRequest>
|
||||
{
|
||||
public GetPositiveAdjustmentSingleValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class GetPositiveAdjustmentSingleHandler : IRequestHandler<GetPositiveAdjustmentSingleRequest, GetPositiveAdjustmentSingleResult>
|
||||
{
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetPositiveAdjustmentSingleHandler(
|
||||
IQueryContext context
|
||||
)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetPositiveAdjustmentSingleResult> Handle(GetPositiveAdjustmentSingleRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var queryData = _context
|
||||
.PositiveAdjustment
|
||||
.AsNoTracking()
|
||||
.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(PositiveAdjustment))
|
||||
.AsQueryable();
|
||||
|
||||
var transactionList = await queryTransactionList.ToListAsync(cancellationToken);
|
||||
|
||||
return new GetPositiveAdjustmentSingleResult
|
||||
{
|
||||
Data = data,
|
||||
TransactionList = transactionList
|
||||
};
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
using Application.Common.Extensions;
|
||||
using AutoMapper;
|
||||
using Domain.Enums;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.PositiveAdjustmentManager.Queries;
|
||||
|
||||
public record GetPositiveAdjustmentStatusListDto
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Name { get; init; }
|
||||
}
|
||||
|
||||
public class GetPositiveAdjustmentStatusListProfile : Profile
|
||||
{
|
||||
public GetPositiveAdjustmentStatusListProfile()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class GetPositiveAdjustmentStatusListResult
|
||||
{
|
||||
public List<GetPositiveAdjustmentStatusListDto>? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetPositiveAdjustmentStatusListRequest : IRequest<GetPositiveAdjustmentStatusListResult>
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public class GetPositiveAdjustmentStatusListHandler : IRequestHandler<GetPositiveAdjustmentStatusListRequest, GetPositiveAdjustmentStatusListResult>
|
||||
{
|
||||
|
||||
public GetPositiveAdjustmentStatusListHandler()
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<GetPositiveAdjustmentStatusListResult> Handle(GetPositiveAdjustmentStatusListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var statuses = Enum.GetValues(typeof(AdjustmentStatus))
|
||||
.Cast<AdjustmentStatus>()
|
||||
.Select(status => new GetPositiveAdjustmentStatusListDto
|
||||
{
|
||||
Id = ((int)status).ToString(),
|
||||
Name = status.ToFriendlyName()
|
||||
})
|
||||
.ToList();
|
||||
|
||||
await Task.CompletedTask;
|
||||
|
||||
return new GetPositiveAdjustmentStatusListResult
|
||||
{
|
||||
Data = statuses
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user