diff --git a/src/CMSMicroservice.Application/Common/UserDisplayName.cs b/src/CMSMicroservice.Application/Common/UserDisplayName.cs new file mode 100644 index 0000000..1c18ec8 --- /dev/null +++ b/src/CMSMicroservice.Application/Common/UserDisplayName.cs @@ -0,0 +1,29 @@ +namespace CMSMicroservice.Application.Common; + +/// +/// نام نمایشی کاربر برای گزارش‌ها؛ اگر نام خالی باشد موبایل یا شناسه. +/// +public static class UserDisplayName +{ + public static string From(string? firstName, string? lastName, string? mobile, long userId) + { + var name = string.Join(" ", + new[] { firstName, lastName }.Where(s => !string.IsNullOrWhiteSpace(s))); + + if (!string.IsNullOrWhiteSpace(name)) + return name; + + if (!string.IsNullOrWhiteSpace(mobile)) + return mobile.Trim(); + + return userId > 0 ? $"کاربر {userId}" : "—"; + } + + public static string From(Domain.Entities.User? user) + { + if (user is null) + return string.Empty; + + return From(user.FirstName, user.LastName, user.Mobile, user.Id); + } +} diff --git a/src/CMSMicroservice.Application/DiscountShopCQ/Queries/GetAllDiscountOrders/GetAllDiscountOrdersQueryHandler.cs b/src/CMSMicroservice.Application/DiscountShopCQ/Queries/GetAllDiscountOrders/GetAllDiscountOrdersQueryHandler.cs index fac1fde..f95415a 100644 --- a/src/CMSMicroservice.Application/DiscountShopCQ/Queries/GetAllDiscountOrders/GetAllDiscountOrdersQueryHandler.cs +++ b/src/CMSMicroservice.Application/DiscountShopCQ/Queries/GetAllDiscountOrders/GetAllDiscountOrdersQueryHandler.cs @@ -1,3 +1,4 @@ +using CMSMicroservice.Application.Common; using CMSMicroservice.Application.Common.Interfaces; using CMSMicroservice.Application.Common.Models; using MediatR; @@ -80,35 +81,58 @@ public class GetAllDiscountOrdersQueryHandler : IRequestHandler o.Created) .Skip((pagination.PageNumber - 1) * pagination.PageSize) .Take(pagination.PageSize) - .Select(o => new AdminOrderDto + .Select(o => new { - Id = o.Id, - UserId = o.UserId, - UserFullName = (o.User.FirstName ?? "") + " " + (o.User.LastName ?? ""), - UserMobile = o.User.Mobile, - TotalAmount = o.TotalAmount, - DiscountBalanceUsed = o.DiscountBalanceUsed, - GatewayAmountPaid = o.GatewayAmountPaid, - VatAmount = o.VatAmount, - PaymentStatus = o.PaymentStatus, - PaymentDate = o.PaymentDate, - DeliveryStatus = o.DeliveryStatus, - DeliveryDate = null, // TODO: Add DeliveryDate to DiscountOrder if needed + o.Id, + o.UserId, + FirstName = o.User.FirstName, + LastName = o.User.LastName, + Mobile = o.User.Mobile, + o.TotalAmount, + o.DiscountBalanceUsed, + o.GatewayAmountPaid, + o.VatAmount, + o.PaymentStatus, + o.PaymentDate, + o.DeliveryStatus, ShippingAddress = o.UserAddress.Address, ReceiverName = o.UserAddress.Title, - ReceiverMobile = o.User.Mobile, - TrackingCode = o.TrackingCode, + o.TrackingCode, AdminNote = o.DeliveryDescription, - Created = o.Created, - LastModified = o.LastModified, + o.Created, + o.LastModified, ItemsCount = o.OrderDetails.Count }) .ToListAsync(cancellationToken); + var orders = rows.Select(o => new AdminOrderDto + { + Id = o.Id, + UserId = o.UserId, + UserFullName = UserDisplayName.From(o.FirstName, o.LastName, o.Mobile, o.UserId), + UserMobile = o.Mobile, + TotalAmount = o.TotalAmount, + DiscountBalanceUsed = o.DiscountBalanceUsed, + GatewayAmountPaid = o.GatewayAmountPaid, + VatAmount = o.VatAmount, + PaymentStatus = o.PaymentStatus, + PaymentDate = o.PaymentDate, + DeliveryStatus = o.DeliveryStatus, + DeliveryDate = null, + ShippingAddress = o.ShippingAddress, + ReceiverName = o.ReceiverName, + ReceiverMobile = o.Mobile, + TrackingCode = o.TrackingCode, + AdminNote = o.AdminNote, + Created = o.Created, + LastModified = o.LastModified, + ItemsCount = o.ItemsCount + }).ToList(); + return new GetAllDiscountOrdersResponseDto { MetaData = new MetaData diff --git a/src/CMSMicroservice.Application/UserOrderCQ/Queries/GetCustomerOrder/GetCustomerOrderQueryHandler.cs b/src/CMSMicroservice.Application/UserOrderCQ/Queries/GetCustomerOrder/GetCustomerOrderQueryHandler.cs index c43e133..c60945a 100644 --- a/src/CMSMicroservice.Application/UserOrderCQ/Queries/GetCustomerOrder/GetCustomerOrderQueryHandler.cs +++ b/src/CMSMicroservice.Application/UserOrderCQ/Queries/GetCustomerOrder/GetCustomerOrderQueryHandler.cs @@ -1,3 +1,4 @@ +using CMSMicroservice.Application.Common; using CMSMicroservice.Application.Common.Exceptions; using CMSMicroservice.Application.Common.Interfaces; using CMSMicroservice.Domain.Entities; @@ -50,7 +51,7 @@ public class GetCustomerOrderQueryHandler : IRequestHandler