Files
CMS/src/CMSMicroservice.Application/UserOrderCQ/Queries/GetUserOrder/GetUserOrderQueryHandler.cs
masoodafar-web f0f48118e7 Add validators and services for Product Galleries and Product Tags
- 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.
2025-12-04 02:40:49 +03:30

53 lines
2.2 KiB
C#

namespace CMSMicroservice.Application.UserOrderCQ.Queries.GetUserOrder;
public class GetUserOrderQueryHandler : IRequestHandler<GetUserOrderQuery, GetUserOrderResponseDto>
{
private readonly IApplicationDbContext _context;
public GetUserOrderQueryHandler(IApplicationDbContext context)
{
_context = context;
}
public async Task<GetUserOrderResponseDto> Handle(GetUserOrderQuery request,
CancellationToken cancellationToken)
{
var response = await _context.UserOrders
.Include(i => i.UserAddress)
.Include(i => i.User)
.Include(i => i.FactorDetails)
.ThenInclude(t => t.Product)
.AsNoTracking()
.Where(x => x.Id == request.Id)
.Select(x => new GetUserOrderResponseDto
{
Id = x.Id,
Amount = x.Amount,
PackageId = x.PackageId ?? 0,
TransactionId = x.TransactionId,
PaymentStatus = x.PaymentStatus,
PaymentDate = x.PaymentDate,
UserId = x.UserId,
UserAddressId = x.UserAddressId,
PaymentMethod = x.PaymentMethod,
UserAddressText = x.UserAddress.Address,
FactorDetails = x.FactorDetails.Select(fd => new GetUserOrderResponseFactorDetail
{
ProductId = fd.ProductId,
ProductTitle = fd.Product.Title,
ProductThumbnailPath = fd.Product.ThumbnailPath,
UnitPrice = fd.UnitPrice,
Count = fd.Count,
UnitDiscountPrice = fd.UnitDiscountPrice
}).ToList(),
DeliveryStatus = x.DeliveryStatus,
TrackingCode = x.TrackingCode,
DeliveryDescription = x.DeliveryDescription,
UserFullName = (x.User.FirstName ?? string.Empty) + " " + (x.User.LastName ?? string.Empty),
UserNationalCode = x.User.NationalCode
})
.FirstOrDefaultAsync(cancellationToken);
return response ?? throw new NotFoundException(nameof(UserOrder), request.Id);
}
}