Files
CMS/src/CMSMicroservice.Application/WarehouseCQ/Commands/CreateWarehouse/CreateWarehouseCommandHandler.cs
T
masoodafar-web dde4c68b2f
Build and Deploy to Kubernetes / build-and-deploy (push) Failing after 2m33s
feat: Implement inventory and warehouse management features
- Add GetLowStockItemsResponseDto and LowStockItemDto for low stock item queries.
- Create CreateStockMovementCommand and its handler for managing stock movements.
- Implement CreateStockMovementCommandValidator for validating stock movement commands.
- Add GetStockMovementsQuery and its handler to retrieve stock movement records.
- Create GetStockMovementsResponseDto and StockMovementListDto for stock movement responses.
- Implement GetStockMovementsByInventoryItemQuery and its handler for fetching movements by inventory item.
- Add CreateWarehouseCommand and its handler for creating new warehouses.
- Implement CreateWarehouseCommandValidator for warehouse creation validation.
- Add DeleteWarehouseCommand and its handler for removing warehouses.
- Implement SetDefaultWarehouseCommand and its handler for setting a default warehouse.
- Create UpdateWarehouseCommand and its handler for updating warehouse details.
- Implement GetAllWarehousesQuery and its handler to retrieve all warehouses.
- Add GetWarehouseQuery and its handler for fetching a specific warehouse by ID.
- Implement SearchWarehousesQuery and its handler for searching warehouses based on criteria.
2026-01-03 11:59:08 +03:30

40 lines
1.3 KiB
C#

using CMSMicroservice.Domain.Entities;
namespace CMSMicroservice.Application.WarehouseCQ.Commands.CreateWarehouse;
public class CreateWarehouseCommandHandler : IRequestHandler<CreateWarehouseCommand, CreateWarehouseResponseDto>
{
private readonly IApplicationDbContext _context;
public CreateWarehouseCommandHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<CreateWarehouseResponseDto> Handle(CreateWarehouseCommand request, CancellationToken cancellationToken)
{
// بررسی تکراری نبودن کد
var codeExists = await _context.Warehouses
.AnyAsync(w => w.Code == request.Code, cancellationToken);
if (codeExists)
{
throw new InvalidOperationException($"Warehouse with code '{request.Code}' already exists");
}
var entity = new Warehouse
{
Name = request.Name,
Code = request.Code,
Address = request.Address,
IsActive = request.IsActive,
IsDefault = request.IsDefault
};
await _context.Warehouses.AddAsync(entity, cancellationToken);
await _context.SaveChangesAsync(cancellationToken);
return new CreateWarehouseResponseDto { Id = entity.Id };
}
}