2024-08-09 21:55:16 +03:30
|
|
|
|
using Netina.Domain.Entities.Warehouses;
|
2023-12-20 10:37:44 +03:30
|
|
|
|
|
2024-04-16 20:01:34 +03:30
|
|
|
|
namespace Netina.Repository.Handlers.Warehouses;
|
2023-12-20 10:37:44 +03:30
|
|
|
|
|
2024-08-09 21:55:16 +03:30
|
|
|
|
public class UpdateShippingCommandHandler(IRepositoryWrapper repositoryWrapper)
|
|
|
|
|
|
: IRequestHandler<UpdateShippingCommand, bool>
|
2023-12-20 10:37:44 +03:30
|
|
|
|
{
|
|
|
|
|
|
public async Task<bool> Handle(UpdateShippingCommand request, CancellationToken cancellationToken)
|
|
|
|
|
|
{
|
2024-08-09 21:55:16 +03:30
|
|
|
|
var ent = await repositoryWrapper.SetRepository<Shipping>().TableNoTracking
|
2023-12-20 10:37:44 +03:30
|
|
|
|
.FirstOrDefaultAsync(s => s.Id == request.Id, cancellationToken);
|
|
|
|
|
|
if (ent == null)
|
|
|
|
|
|
throw new AppException("Shipping not found", ApiResultStatusCode.NotFound);
|
|
|
|
|
|
|
2024-02-09 21:43:14 +03:30
|
|
|
|
var newEnt = Shipping.Create(request.Name, request.WarehouseName, request.IsExpressShipping, request.IsShipBySeller,
|
2024-02-12 22:01:15 +03:30
|
|
|
|
request.IsOriginalWarehouse,request.DeliveryCost,request.WorkingDays);
|
2023-12-20 10:37:44 +03:30
|
|
|
|
newEnt.Id = ent.Id;
|
2024-02-04 16:38:23 +03:30
|
|
|
|
newEnt.CreatedAt = ent.CreatedAt;
|
|
|
|
|
|
newEnt.CreatedBy = ent.CreatedBy;
|
2024-08-09 21:55:16 +03:30
|
|
|
|
repositoryWrapper.SetRepository<Shipping>().Update(newEnt);
|
|
|
|
|
|
await repositoryWrapper.SaveChangesAsync(cancellationToken);
|
2023-12-20 10:37:44 +03:30
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|