f0f48118e7
- Implemented Create, Delete, Get, and Update validators for Product Galleries. - Added Create, Delete, Get, and Update validators for Product Tags. - Created service classes for handling Discount Categories, Discount Orders, Discount Products, Discount Shopping Cart, Product Categories, Product Galleries, and Product Tags. - Each service class integrates with CQRS for command and query handling. - Established mapping profiles for Product Galleries.
47 lines
1.4 KiB
C#
47 lines
1.4 KiB
C#
using CMSMicroservice.Application.Common.Interfaces;
|
|
using MediatR;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace CMSMicroservice.Application.DiscountShopCQ.Commands.UpdateOrderStatus;
|
|
|
|
public class UpdateOrderStatusCommandHandler : IRequestHandler<UpdateOrderStatusCommand, UpdateOrderStatusResponseDto>
|
|
{
|
|
private readonly IApplicationDbContext _context;
|
|
|
|
public UpdateOrderStatusCommandHandler(IApplicationDbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public async Task<UpdateOrderStatusResponseDto> Handle(UpdateOrderStatusCommand request, CancellationToken cancellationToken)
|
|
{
|
|
var order = await _context.DiscountOrders
|
|
.FirstOrDefaultAsync(o => o.Id == request.OrderId, cancellationToken);
|
|
|
|
if (order == null)
|
|
{
|
|
return new UpdateOrderStatusResponseDto
|
|
{
|
|
Success = false,
|
|
Message = "سفارش یافت نشد"
|
|
};
|
|
}
|
|
|
|
// بهروزرسانی وضعیت
|
|
order.DeliveryStatus = request.DeliveryStatus;
|
|
|
|
if (!string.IsNullOrEmpty(request.TrackingCode))
|
|
{
|
|
order.TrackingCode = request.TrackingCode;
|
|
}
|
|
|
|
await _context.SaveChangesAsync(cancellationToken);
|
|
|
|
return new UpdateOrderStatusResponseDto
|
|
{
|
|
Success = true,
|
|
Message = "وضعیت سفارش بهروزرسانی شد"
|
|
};
|
|
}
|
|
}
|