initial commit
This commit is contained in:
+68
@@ -0,0 +1,68 @@
|
||||
using Application.Common.Repositories;
|
||||
using Application.Features.NumberSequenceManager;
|
||||
using Domain.Entities;
|
||||
using Domain.Enums;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.NegativeAdjustmentManager.Commands;
|
||||
|
||||
public class CreateNegativeAdjustmentResult
|
||||
{
|
||||
public NegativeAdjustment? Data { get; set; }
|
||||
}
|
||||
|
||||
public class CreateNegativeAdjustmentRequest : IRequest<CreateNegativeAdjustmentResult>
|
||||
{
|
||||
public string? Number { get; init; }
|
||||
public DateTime? AdjustmentDate { get; init; }
|
||||
public string? Status { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public string? CreatedById { get; init; }
|
||||
}
|
||||
|
||||
public class CreateNegativeAdjustmentValidator : AbstractValidator<CreateNegativeAdjustmentRequest>
|
||||
{
|
||||
public CreateNegativeAdjustmentValidator()
|
||||
{
|
||||
RuleFor(x => x.AdjustmentDate).NotEmpty();
|
||||
RuleFor(x => x.Status).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class CreateNegativeAdjustmentHandler : IRequestHandler<CreateNegativeAdjustmentRequest, CreateNegativeAdjustmentResult>
|
||||
{
|
||||
private readonly ICommandRepository<NegativeAdjustment> _repository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly NumberSequenceService _numberSequenceService;
|
||||
|
||||
public CreateNegativeAdjustmentHandler(
|
||||
ICommandRepository<NegativeAdjustment> repository,
|
||||
IUnitOfWork unitOfWork,
|
||||
NumberSequenceService numberSequenceService
|
||||
)
|
||||
{
|
||||
_repository = repository;
|
||||
_unitOfWork = unitOfWork;
|
||||
_numberSequenceService = numberSequenceService;
|
||||
}
|
||||
|
||||
public async Task<CreateNegativeAdjustmentResult> Handle(CreateNegativeAdjustmentRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = new NegativeAdjustment();
|
||||
entity.CreatedById = request.CreatedById;
|
||||
|
||||
entity.Number = _numberSequenceService.GenerateNumber(nameof(NegativeAdjustment), "", "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 CreateNegativeAdjustmentResult
|
||||
{
|
||||
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.NegativeAdjustmentManager.Commands;
|
||||
|
||||
public class DeleteNegativeAdjustmentResult
|
||||
{
|
||||
public NegativeAdjustment? Data { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteNegativeAdjustmentRequest : IRequest<DeleteNegativeAdjustmentResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? DeletedById { get; init; }
|
||||
}
|
||||
|
||||
public class DeleteNegativeAdjustmentValidator : AbstractValidator<DeleteNegativeAdjustmentRequest>
|
||||
{
|
||||
public DeleteNegativeAdjustmentValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class DeleteNegativeAdjustmentHandler : IRequestHandler<DeleteNegativeAdjustmentRequest, DeleteNegativeAdjustmentResult>
|
||||
{
|
||||
private readonly ICommandRepository<NegativeAdjustment> _repository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public DeleteNegativeAdjustmentHandler(
|
||||
ICommandRepository<NegativeAdjustment> repository,
|
||||
IUnitOfWork unitOfWork,
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_repository = repository;
|
||||
_unitOfWork = unitOfWork;
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<DeleteNegativeAdjustmentResult> Handle(DeleteNegativeAdjustmentRequest 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(NegativeAdjustment),
|
||||
entity.AdjustmentDate,
|
||||
(InventoryTransactionStatus?)entity.Status,
|
||||
entity.IsDeleted,
|
||||
entity.UpdatedById,
|
||||
null,
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
return new DeleteNegativeAdjustmentResult
|
||||
{
|
||||
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.NegativeAdjustmentManager.Commands;
|
||||
|
||||
public class UpdateNegativeAdjustmentResult
|
||||
{
|
||||
public NegativeAdjustment? Data { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateNegativeAdjustmentRequest : IRequest<UpdateNegativeAdjustmentResult>
|
||||
{
|
||||
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 UpdateNegativeAdjustmentValidator : AbstractValidator<UpdateNegativeAdjustmentRequest>
|
||||
{
|
||||
public UpdateNegativeAdjustmentValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
RuleFor(x => x.AdjustmentDate).NotEmpty();
|
||||
RuleFor(x => x.Status).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class UpdateNegativeAdjustmentHandler : IRequestHandler<UpdateNegativeAdjustmentRequest, UpdateNegativeAdjustmentResult>
|
||||
{
|
||||
private readonly ICommandRepository<NegativeAdjustment> _repository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public UpdateNegativeAdjustmentHandler(
|
||||
ICommandRepository<NegativeAdjustment> repository,
|
||||
IUnitOfWork unitOfWork,
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_repository = repository;
|
||||
_unitOfWork = unitOfWork;
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<UpdateNegativeAdjustmentResult> Handle(UpdateNegativeAdjustmentRequest 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(NegativeAdjustment),
|
||||
entity.AdjustmentDate,
|
||||
(InventoryTransactionStatus?)entity.Status,
|
||||
entity.IsDeleted,
|
||||
entity.UpdatedById,
|
||||
null,
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
return new UpdateNegativeAdjustmentResult
|
||||
{
|
||||
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.NegativeAdjustmentManager.Queries;
|
||||
|
||||
public record GetNegativeAdjustmentListDto
|
||||
{
|
||||
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 GetNegativeAdjustmentListProfile : Profile
|
||||
{
|
||||
public GetNegativeAdjustmentListProfile()
|
||||
{
|
||||
CreateMap<NegativeAdjustment, GetNegativeAdjustmentListDto>()
|
||||
.ForMember(
|
||||
dest => dest.StatusName,
|
||||
opt => opt.MapFrom(src => src.Status.HasValue ? src.Status.Value.ToFriendlyName() : string.Empty)
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class GetNegativeAdjustmentListResult
|
||||
{
|
||||
public List<GetNegativeAdjustmentListDto>? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetNegativeAdjustmentListRequest : IRequest<GetNegativeAdjustmentListResult>
|
||||
{
|
||||
public bool IsDeleted { get; init; } = false;
|
||||
}
|
||||
|
||||
|
||||
public class GetNegativeAdjustmentListHandler : IRequestHandler<GetNegativeAdjustmentListRequest, GetNegativeAdjustmentListResult>
|
||||
{
|
||||
private readonly IMapper _mapper;
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetNegativeAdjustmentListHandler(IMapper mapper, IQueryContext context)
|
||||
{
|
||||
_mapper = mapper;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetNegativeAdjustmentListResult> Handle(GetNegativeAdjustmentListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var query = _context
|
||||
.NegativeAdjustment
|
||||
.AsNoTracking()
|
||||
.ApplyIsDeletedFilter(request.IsDeleted)
|
||||
.AsQueryable();
|
||||
|
||||
var entities = await query.ToListAsync(cancellationToken);
|
||||
|
||||
var dtos = _mapper.Map<List<GetNegativeAdjustmentListDto>>(entities);
|
||||
|
||||
return new GetNegativeAdjustmentListResult
|
||||
{
|
||||
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.NegativeAdjustmentManager.Queries;
|
||||
|
||||
|
||||
public class GetNegativeAdjustmentSingleProfile : Profile
|
||||
{
|
||||
public GetNegativeAdjustmentSingleProfile()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class GetNegativeAdjustmentSingleResult
|
||||
{
|
||||
public NegativeAdjustment? Data { get; init; }
|
||||
public List<InventoryTransaction>? TransactionList { get; init; }
|
||||
}
|
||||
|
||||
public class GetNegativeAdjustmentSingleRequest : IRequest<GetNegativeAdjustmentSingleResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
}
|
||||
|
||||
public class GetNegativeAdjustmentSingleValidator : AbstractValidator<GetNegativeAdjustmentSingleRequest>
|
||||
{
|
||||
public GetNegativeAdjustmentSingleValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class GetNegativeAdjustmentSingleHandler : IRequestHandler<GetNegativeAdjustmentSingleRequest, GetNegativeAdjustmentSingleResult>
|
||||
{
|
||||
private readonly IQueryContext _context;
|
||||
|
||||
public GetNegativeAdjustmentSingleHandler(
|
||||
IQueryContext context
|
||||
)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetNegativeAdjustmentSingleResult> Handle(GetNegativeAdjustmentSingleRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var queryData = _context
|
||||
.NegativeAdjustment
|
||||
.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(NegativeAdjustment))
|
||||
.AsQueryable();
|
||||
|
||||
var transactionList = await queryTransactionList.ToListAsync(cancellationToken);
|
||||
|
||||
return new GetNegativeAdjustmentSingleResult
|
||||
{
|
||||
Data = data,
|
||||
TransactionList = transactionList
|
||||
};
|
||||
}
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
using Application.Common.Extensions;
|
||||
using AutoMapper;
|
||||
using Domain.Enums;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.NegativeAdjustmentManager.Queries;
|
||||
|
||||
public record GetNegativeAdjustmentStatusListDto
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? Name { get; init; }
|
||||
}
|
||||
|
||||
public class GetNegativeAdjustmentStatusListProfile : Profile
|
||||
{
|
||||
public GetNegativeAdjustmentStatusListProfile()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class GetNegativeAdjustmentStatusListResult
|
||||
{
|
||||
public List<GetNegativeAdjustmentStatusListDto>? Data { get; init; }
|
||||
}
|
||||
|
||||
public class GetNegativeAdjustmentStatusListRequest : IRequest<GetNegativeAdjustmentStatusListResult>
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public class GetNegativeAdjustmentStatusListHandler : IRequestHandler<GetNegativeAdjustmentStatusListRequest, GetNegativeAdjustmentStatusListResult>
|
||||
{
|
||||
|
||||
public GetNegativeAdjustmentStatusListHandler()
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<GetNegativeAdjustmentStatusListResult> Handle(GetNegativeAdjustmentStatusListRequest request, CancellationToken cancellationToken)
|
||||
{
|
||||
var statuses = Enum.GetValues(typeof(AdjustmentStatus))
|
||||
.Cast<AdjustmentStatus>()
|
||||
.Select(status => new GetNegativeAdjustmentStatusListDto
|
||||
{
|
||||
Id = ((int)status).ToString(),
|
||||
Name = status.ToFriendlyName()
|
||||
})
|
||||
.ToList();
|
||||
|
||||
await Task.CompletedTask;
|
||||
|
||||
return new GetNegativeAdjustmentStatusListResult
|
||||
{
|
||||
Data = statuses
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user