fix(CancelOrder)
parent
8c7e09e5e6
commit
1137fde70b
|
@ -24,6 +24,11 @@ public class OrderController : ICarterModule
|
|||
.RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser().RequireClaim(CustomClaimType.Permission, ApplicationPermission.ManageOrders))
|
||||
.HasApiVersion(1.0);
|
||||
|
||||
group.MapPost("{id}/cancel", CancelOrderStepAsync)
|
||||
.WithDisplayName("ConfirmOrderStep")
|
||||
.RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser().RequireClaim(CustomClaimType.Permission, ApplicationPermission.ManageOrders))
|
||||
.HasApiVersion(1.0);
|
||||
|
||||
group.MapDelete("{id}", DeleteAsync)
|
||||
.WithDisplayName("DeleteOneOrder")
|
||||
.RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser().RequireClaim(CustomClaimType.Permission, ApplicationPermission.ManageOrders))
|
||||
|
@ -40,6 +45,9 @@ public class OrderController : ICarterModule
|
|||
private async Task<IResult> ConfirmOrderStepAsync(Guid id, [FromQuery] OrderStatus nextOrderStatus, [FromQuery]string? trackingCode, [FromServices] IMediator mediator, CancellationToken cancellationToken)
|
||||
=> TypedResults.Ok(await mediator.Send(new ConfirmOrderStepCommand(id, nextOrderStatus,TrackingCode:trackingCode), cancellationToken));
|
||||
|
||||
private async Task<IResult> CancelOrderStepAsync(Guid id, [FromServices] IMediator mediator, CancellationToken cancellationToken)
|
||||
=> TypedResults.Ok(await mediator.Send(new CancelOrderStepCommand(id), cancellationToken));
|
||||
|
||||
public async Task<IResult> GetAllAsync(IMediator mediator,
|
||||
[FromQuery]string? factorCode,
|
||||
[FromQuery]long? selectedDate,
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
namespace Netina.Core.EntityServices.OrderHandlers;
|
||||
|
||||
public class CancelOrderStepCommandHandler (IRepositoryWrapper repositoryWrapper) : IRequestHandler<CancelOrderStepCommand,bool>
|
||||
{
|
||||
public async Task<bool> Handle(CancelOrderStepCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var order = await repositoryWrapper.SetRepository<Order>()
|
||||
.TableNoTracking
|
||||
.FirstOrDefaultAsync(o => o.Id == request.OrderId, cancellationToken);
|
||||
if (order == null)
|
||||
throw new AppException("Order not found", ApiResultStatusCode.NotFound);
|
||||
|
||||
order.SetOrderStatus(OrderStatus.Canceled);
|
||||
|
||||
repositoryWrapper.SetRepository<Order>().Update(order);
|
||||
await repositoryWrapper.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ public sealed record CreateBaseOrderCommand(Guid UserId) : IRequest<Order>;
|
|||
|
||||
public sealed record CalculateOrderCommand(Guid OrderId , bool NamoosiCalculate = false) : IRequest<Order>;
|
||||
public sealed record ConfirmOrderStepCommand(Guid OrderId , OrderStatus NextOrderStatus,string? TrackingCode) : IRequest<bool>;
|
||||
public sealed record CancelOrderStepCommand(Guid OrderId) : IRequest<bool>;
|
||||
|
||||
public sealed record GetOrderInvoiceCommand(Guid OrderId) : IRequest<byte[]>;
|
||||
public sealed record DeleteOrderCommand(Guid OrderId) : IRequest<bool>;
|
|
@ -2,19 +2,12 @@
|
|||
|
||||
namespace Netina.Repository.Handlers.Products;
|
||||
|
||||
public class UpdateProductCommandHandler : IRequestHandler<UpdateProductCommand, bool>
|
||||
public class UpdateProductCommandHandler(IRepositoryWrapper repositoryWrapper, IMediator mediator)
|
||||
: IRequestHandler<UpdateProductCommand, bool>
|
||||
{
|
||||
private readonly IRepositoryWrapper _repositoryWrapper;
|
||||
private readonly IMediator _mediator;
|
||||
|
||||
public UpdateProductCommandHandler(IRepositoryWrapper repositoryWrapper,IMediator mediator)
|
||||
{
|
||||
_repositoryWrapper = repositoryWrapper;
|
||||
_mediator = mediator;
|
||||
}
|
||||
public async Task<bool> Handle(UpdateProductCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var ent = await _repositoryWrapper.SetRepository<Product>().TableNoTracking
|
||||
var ent = await repositoryWrapper.SetRepository<Product>().TableNoTracking
|
||||
.FirstOrDefaultAsync(e => e.Id == request.Id, cancellationToken);
|
||||
if (ent == null)
|
||||
throw new AppException("Product not found", ApiResultStatusCode.NotFound);
|
||||
|
@ -34,14 +27,14 @@ public class UpdateProductCommandHandler : IRequestHandler<UpdateProductCommand,
|
|||
newEnt.CreatedAt = ent.CreatedAt;
|
||||
newEnt.CreatedBy = ent.CreatedBy;
|
||||
|
||||
var dbSpecifications = await _repositoryWrapper.SetRepository<Specification>().TableNoTracking
|
||||
var dbSpecifications = await repositoryWrapper.SetRepository<Specification>().TableNoTracking
|
||||
.Where(s => s.ProductId == ent.Id).ToListAsync(cancellationToken);
|
||||
foreach (var dbSpecification in dbSpecifications)
|
||||
{
|
||||
if (request.Specifications.FirstOrDefault(s => s.Id != dbSpecification.Id) == null)
|
||||
{
|
||||
_repositoryWrapper.SetRepository<Specification>().Delete(dbSpecification);
|
||||
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
|
||||
repositoryWrapper.SetRepository<Specification>().Delete(dbSpecification);
|
||||
await repositoryWrapper.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
foreach (var specification in request.Specifications.Where(s => s.Id == default))
|
||||
|
@ -51,14 +44,14 @@ public class UpdateProductCommandHandler : IRequestHandler<UpdateProductCommand,
|
|||
|
||||
|
||||
|
||||
var dbFiles = await _repositoryWrapper.SetRepository<ProductStorageFile>().TableNoTracking
|
||||
var dbFiles = await repositoryWrapper.SetRepository<ProductStorageFile>().TableNoTracking
|
||||
.Where(s => s.ProductId == ent.Id).ToListAsync(cancellationToken);
|
||||
foreach (var dbFile in dbFiles)
|
||||
{
|
||||
if (request.Files.FirstOrDefault(s => s.Id == dbFile.Id)==null)
|
||||
{
|
||||
_repositoryWrapper.SetRepository<ProductStorageFile>().Delete(dbFile);
|
||||
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
|
||||
repositoryWrapper.SetRepository<ProductStorageFile>().Delete(dbFile);
|
||||
await repositoryWrapper.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
foreach (var file in request.Files.Where(f=>f.Id==default))
|
||||
|
@ -67,8 +60,8 @@ public class UpdateProductCommandHandler : IRequestHandler<UpdateProductCommand,
|
|||
}
|
||||
|
||||
|
||||
_repositoryWrapper.SetRepository<Product>().Update(newEnt);
|
||||
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
|
||||
repositoryWrapper.SetRepository<Product>().Update(newEnt);
|
||||
await repositoryWrapper.SaveChangesAsync(cancellationToken);
|
||||
|
||||
if (request.IsSpecialOffer)
|
||||
{
|
||||
|
@ -81,12 +74,12 @@ public class UpdateProductCommandHandler : IRequestHandler<UpdateProductCommand,
|
|||
if (request.SpecialOffer.Id == default)
|
||||
{
|
||||
var discountRequest = discount.Adapt<CreateDiscountCommand>();
|
||||
await _mediator.Send(discountRequest, cancellationToken);
|
||||
await mediator.Send(discountRequest, cancellationToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
var discountRequest = discount.Adapt<UpdateDiscountCommand>();
|
||||
await _mediator.Send(discountRequest, cancellationToken);
|
||||
await mediator.Send(discountRequest, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue