initial commit
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
using Application.Common.Repositories;
|
||||
using Application.Features.NumberSequenceManager;
|
||||
using Domain.Entities;
|
||||
using Domain.Enums;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.StockCountManager.Commands;
|
||||
|
||||
public class CreateStockCountResult
|
||||
{
|
||||
public StockCount? Data { get; set; }
|
||||
}
|
||||
|
||||
public class CreateStockCountRequest : IRequest<CreateStockCountResult>
|
||||
{
|
||||
public DateTime? CountDate { get; init; }
|
||||
public string? Status { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public string? WarehouseId { get; init; }
|
||||
public string? CreatedById { get; init; }
|
||||
}
|
||||
|
||||
public class CreateStockCountValidator : AbstractValidator<CreateStockCountRequest>
|
||||
{
|
||||
public CreateStockCountValidator()
|
||||
{
|
||||
RuleFor(x => x.CountDate).NotEmpty();
|
||||
RuleFor(x => x.Status).NotEmpty();
|
||||
RuleFor(x => x.WarehouseId).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class CreateStockCountHandler : IRequestHandler<CreateStockCountRequest, CreateStockCountResult>
|
||||
{
|
||||
private readonly ICommandRepository<StockCount> _repository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly NumberSequenceService _numberSequenceService;
|
||||
|
||||
public CreateStockCountHandler(
|
||||
ICommandRepository<StockCount> repository,
|
||||
IUnitOfWork unitOfWork,
|
||||
NumberSequenceService numberSequenceService
|
||||
)
|
||||
{
|
||||
_repository = repository;
|
||||
_unitOfWork = unitOfWork;
|
||||
_numberSequenceService = numberSequenceService;
|
||||
}
|
||||
|
||||
public async Task<CreateStockCountResult> Handle(CreateStockCountRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = new StockCount();
|
||||
entity.CreatedById = request.CreatedById;
|
||||
|
||||
entity.Number = _numberSequenceService.GenerateNumber(nameof(StockCount), "", "SC");
|
||||
entity.CountDate = request.CountDate;
|
||||
entity.Status = (StockCountStatus)int.Parse(request.Status!);
|
||||
entity.Description = request.Description;
|
||||
entity.WarehouseId = request.WarehouseId;
|
||||
|
||||
await _repository.CreateAsync(entity, cancellationToken);
|
||||
await _unitOfWork.SaveAsync(cancellationToken);
|
||||
|
||||
return new CreateStockCountResult
|
||||
{
|
||||
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.StockCountManager.Commands;
|
||||
|
||||
public class DeleteStockCountResult
|
||||
{
|
||||
public StockCount? Data { get; set; }
|
||||
}
|
||||
|
||||
public class DeleteStockCountRequest : IRequest<DeleteStockCountResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public string? DeletedById { get; init; }
|
||||
}
|
||||
|
||||
public class DeleteStockCountValidator : AbstractValidator<DeleteStockCountRequest>
|
||||
{
|
||||
public DeleteStockCountValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class DeleteStockCountHandler : IRequestHandler<DeleteStockCountRequest, DeleteStockCountResult>
|
||||
{
|
||||
private readonly ICommandRepository<StockCount> _repository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public DeleteStockCountHandler(
|
||||
ICommandRepository<StockCount> repository,
|
||||
IUnitOfWork unitOfWork,
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_repository = repository;
|
||||
_unitOfWork = unitOfWork;
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<DeleteStockCountResult> Handle(DeleteStockCountRequest 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(StockCount),
|
||||
entity.CountDate,
|
||||
(InventoryTransactionStatus?)entity.Status,
|
||||
entity.IsDeleted,
|
||||
entity.UpdatedById,
|
||||
null,
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
return new DeleteStockCountResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
using Application.Common.Repositories;
|
||||
using Application.Features.InventoryTransactionManager;
|
||||
using Domain.Entities;
|
||||
using Domain.Enums;
|
||||
using FluentValidation;
|
||||
using MediatR;
|
||||
|
||||
namespace Application.Features.StockCountManager.Commands;
|
||||
|
||||
public class UpdateStockCountResult
|
||||
{
|
||||
public StockCount? Data { get; set; }
|
||||
}
|
||||
|
||||
public class UpdateStockCountRequest : IRequest<UpdateStockCountResult>
|
||||
{
|
||||
public string? Id { get; init; }
|
||||
public DateTime? CountDate { get; init; }
|
||||
public string? Status { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public string? WarehouseId { get; init; }
|
||||
public string? UpdatedById { get; init; }
|
||||
}
|
||||
|
||||
public class UpdateStockCountValidator : AbstractValidator<UpdateStockCountRequest>
|
||||
{
|
||||
public UpdateStockCountValidator()
|
||||
{
|
||||
RuleFor(x => x.Id).NotEmpty();
|
||||
RuleFor(x => x.CountDate).NotEmpty();
|
||||
RuleFor(x => x.Status).NotEmpty();
|
||||
RuleFor(x => x.WarehouseId).NotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
public class UpdateStockCountHandler : IRequestHandler<UpdateStockCountRequest, UpdateStockCountResult>
|
||||
{
|
||||
private readonly ICommandRepository<StockCount> _repository;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly InventoryTransactionService _inventoryTransactionService;
|
||||
|
||||
public UpdateStockCountHandler(
|
||||
ICommandRepository<StockCount> repository,
|
||||
IUnitOfWork unitOfWork,
|
||||
InventoryTransactionService inventoryTransactionService
|
||||
)
|
||||
{
|
||||
_repository = repository;
|
||||
_unitOfWork = unitOfWork;
|
||||
_inventoryTransactionService = inventoryTransactionService;
|
||||
}
|
||||
|
||||
public async Task<UpdateStockCountResult> Handle(UpdateStockCountRequest 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.CountDate = request.CountDate;
|
||||
entity.Status = (StockCountStatus)int.Parse(request.Status!);
|
||||
entity.Description = request.Description;
|
||||
entity.WarehouseId = request.WarehouseId;
|
||||
|
||||
_repository.Update(entity);
|
||||
await _unitOfWork.SaveAsync(cancellationToken);
|
||||
|
||||
await _inventoryTransactionService.PropagateParentUpdate(
|
||||
entity.Id,
|
||||
nameof(StockCount),
|
||||
entity.CountDate,
|
||||
(InventoryTransactionStatus?)entity.Status,
|
||||
entity.IsDeleted,
|
||||
entity.UpdatedById,
|
||||
entity.WarehouseId,
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
return new UpdateStockCountResult
|
||||
{
|
||||
Data = entity
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user