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
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user