Skip to content

Commit f4c0493

Browse files
DangDang
authored andcommitted
feat: Improve customer name fallback for accounts without name
- Add DisplayName computed property to User entity with fallback logic: Name -> Email -> Username - Update dashboard recent-orders to use DisplayName property for cleaner code - Handle cases where customer accounts are created without name field - Improve error handling in dashboard queries - Remove unused using directive from User.cs
1 parent 9482e01 commit f4c0493

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

VehicleShowroomManagement/src/Application/Features/Dashboard/Queries/GetRecentOrders/GetRecentOrdersQueryHandler.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ public async Task<List<RecentOrderDto>> Handle(GetRecentOrdersQuery request, Can
3838
{
3939
OrderId = order.Id,
4040
OrderNumber = order.Id, // Using ID as order number
41-
CustomerName = customer?.Name ?? customer?.Email ?? $"Customer ID: {order.CustomerId}",
41+
CustomerName = customer?.DisplayName ?? $"Customer ID: {order.CustomerId}",
4242
VehicleModel = model?.Name ?? order.ModelNumber,
4343
TotalAmount = order.SalePrice,
4444
Status = order.Status.ToString(),
4545
OrderDate = order.OrderDate,
46-
SalesPersonName = dealer?.Name ?? dealer?.Email ?? "No Dealer Assigned"
46+
SalesPersonName = dealer?.DisplayName ?? "No Dealer Assigned"
4747
});
4848
}
4949
catch (Exception)
@@ -53,7 +53,7 @@ public async Task<List<RecentOrderDto>> Handle(GetRecentOrdersQuery request, Can
5353
{
5454
OrderId = order.Id,
5555
OrderNumber = order.Id,
56-
CustomerName = $"Error loading customer: {order.CustomerId}",
56+
CustomerName = $"Customer ID: {order.CustomerId}",
5757
VehicleModel = order.ModelNumber,
5858
TotalAmount = order.SalePrice,
5959
Status = order.Status.ToString(),

VehicleShowroomManagement/src/Domain/Entities/User.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using MongoDB.Bson;
32
using MongoDB.Bson.Serialization.Attributes;
43

@@ -148,5 +147,13 @@ public void Restore()
148147
public bool IsActive => Status == "Active";
149148
public bool IsDeleted => DeletedAt.HasValue;
150149
public bool IsEmployee => HireDate.HasValue;
150+
151+
/// <summary>
152+
/// Gets the best available display name for the user
153+
/// Priority: Name -> Email -> Username
154+
/// </summary>
155+
public string DisplayName => !string.IsNullOrWhiteSpace(Name) ? Name
156+
: !string.IsNullOrWhiteSpace(Email) ? Email
157+
: Username;
151158
}
152159
}

0 commit comments

Comments
 (0)