feat(pos): implement order payment flow and update order aggregate status handling.

This commit is contained in:
Ho Ngoc Hai
2026-03-05 08:05:19 +07:00
parent 0901e91673
commit cfcdbd069d
4 changed files with 46 additions and 14 deletions

View File

@@ -46,10 +46,10 @@ public class Order : Entity, IAggregateRoot
public Guid? TableId => _tableId;
/// <summary>
/// EN: Order status.
/// VI: Trạng thái đơn hàng.
/// EN: Order status (resolved from StatusId when loaded from DB).
/// VI: Trạng thái đơn hàng (resolve từ StatusId khi load từ DB).
/// </summary>
public OrderStatus Status => _status;
public OrderStatus Status => _status ?? Enumeration.FromValue<OrderStatus>(StatusId);
/// <summary>
/// EN: Status ID for EF Core mapping.
@@ -134,8 +134,8 @@ public class Order : Entity, IAggregateRoot
/// </summary>
public void MarkAsValidated()
{
if (_status != OrderStatus.Draft)
throw new DomainException($"Cannot validate order with status {_status.Name}");
if (Status != OrderStatus.Draft)
throw new DomainException($"Cannot validate order with status {Status.Name}");
if (!_items.Any())
throw new DomainException("Cannot validate order with no items");
@@ -150,8 +150,8 @@ public class Order : Entity, IAggregateRoot
/// </summary>
public void MarkAsPaid()
{
if (_status != OrderStatus.Validated)
throw new DomainException($"Cannot mark as paid order with status {_status.Name}");
if (Status != OrderStatus.Validated)
throw new DomainException($"Cannot mark as paid order with status {Status.Name}");
_status = OrderStatus.Paid;
StatusId = OrderStatus.Paid.Id;
@@ -166,8 +166,8 @@ public class Order : Entity, IAggregateRoot
/// </summary>
public void MarkAsProcessing()
{
if (_status != OrderStatus.Paid)
throw new DomainException($"Cannot process order with status {_status.Name}");
if (Status != OrderStatus.Paid)
throw new DomainException($"Cannot process order with status {Status.Name}");
_status = OrderStatus.Processing;
StatusId = OrderStatus.Processing.Id;
@@ -180,8 +180,8 @@ public class Order : Entity, IAggregateRoot
/// </summary>
public void MarkAsCompleted()
{
if (_status != OrderStatus.Processing)
throw new DomainException($"Cannot complete order with status {_status.Name}");
if (Status != OrderStatus.Processing)
throw new DomainException($"Cannot complete order with status {Status.Name}");
_status = OrderStatus.Completed;
StatusId = OrderStatus.Completed.Id;
@@ -196,9 +196,9 @@ public class Order : Entity, IAggregateRoot
/// </summary>
public void Cancel(string reason)
{
if (_status == OrderStatus.Completed)
if (Status == OrderStatus.Completed)
throw new DomainException("Cannot cancel completed order");
if (_status == OrderStatus.Cancelled)
if (Status == OrderStatus.Cancelled)
throw new DomainException("Order is already cancelled");
_status = OrderStatus.Cancelled;