From aeb55072ccc92daa5be40863b5d2cbf3d2010007 Mon Sep 17 00:00:00 2001 From: Ho Ngoc Hai Date: Wed, 25 Mar 2026 18:16:55 +0700 Subject: [PATCH] fix(merchant): fix NullReferenceException in Shop.Publish() and build errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Shop.Publish(): use StatusId (persisted int) instead of _status (null when EF Core loads entity without navigation property hydration) - Shop.SetInactive(): same fix for _status null check - SubscribeCommand: fix 'userId' → 'request.UserId' build error - StaffQueries: fix 'userId' → 'request.UserId' build error Co-Authored-By: Claude Opus 4.6 (1M context) --- .../Commands/Subscriptions/SubscribeCommand.cs | 2 +- .../Application/Queries/Staff/StaffQueries.cs | 2 +- .../AggregatesModel/ShopAggregate/Shop.cs | 8 +++++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/services/merchant-service-net/src/MerchantService.API/Application/Commands/Subscriptions/SubscribeCommand.cs b/services/merchant-service-net/src/MerchantService.API/Application/Commands/Subscriptions/SubscribeCommand.cs index 3e9a6672..949d3d01 100644 --- a/services/merchant-service-net/src/MerchantService.API/Application/Commands/Subscriptions/SubscribeCommand.cs +++ b/services/merchant-service-net/src/MerchantService.API/Application/Commands/Subscriptions/SubscribeCommand.cs @@ -48,7 +48,7 @@ public class SubscribeCommandHandler : IRequestHandler public void Publish() { - if (_status != ShopStatus.Draft && _status != ShopStatus.Inactive) - throw new DomainException($"Cannot publish shop with status {_status.Name}"); + // EN: Use StatusId (persisted int) instead of _status (may be null when EF loads entity). + // VI: Dùng StatusId (int đã persist) thay vì _status (có thể null khi EF load entity). + if (StatusId != ShopStatus.Draft.Id && StatusId != ShopStatus.Inactive.Id) + throw new DomainException($"Cannot publish shop with status ID {StatusId}"); _status = ShopStatus.Active; StatusId = ShopStatus.Active.Id; @@ -297,7 +299,7 @@ public partial class Shop : Entity, IAggregateRoot /// public void SetInactive() { - if (_status == ShopStatus.Closed) + if (StatusId == ShopStatus.Closed.Id) throw new DomainException("Cannot change status of closed shop"); _status = ShopStatus.Inactive;