Browse Source

Add new methods to order aggregate root and modify saga process

pull/223/head
Christian Arenas 7 years ago
parent
commit
c89cc06f94
7 changed files with 122 additions and 37 deletions
  1. +0
    -5
      src/Services/Ordering/Ordering.API/Application/Sagas/Saga.cs
  2. +58
    -6
      src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs
  3. +2
    -2
      src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/OrderStatus.cs
  4. +23
    -0
      src/Services/Ordering/Ordering.Domain/Events/OrderStatusChangedToAwaitingValidationDomainEvent.cs
  5. +23
    -0
      src/Services/Ordering/Ordering.Domain/Events/OrderStatusChangedToPaidDomainEvent.cs
  6. +16
    -0
      src/Services/Ordering/Ordering.Domain/Events/OrderStatusChangedToStockConfirmedDomainEvent.cs
  7. +0
    -24
      src/Services/Ordering/Ordering.Domain/Events/OrderStockMethodVerifiedDomainEvent.cs

+ 0
- 5
src/Services/Ordering/Ordering.API/Application/Sagas/Saga.cs View File

@ -17,10 +17,5 @@ namespace Ordering.API.Application.Sagas
public abstract TEntity FindSagaById(int id);
public abstract Task<bool> SaveChangesAsync();
//{
// var ctx = context ?? _dbContext;
// var result = await ctx.SaveChangesAsync();
// return result > 0;
//}
}
}

+ 58
- 6
src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/Order.cs View File

@ -1,5 +1,6 @@
using Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork;
using Ordering.Domain.Events;
using Ordering.Domain.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
@ -93,18 +94,38 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
_buyerId = id;
}
public void SetOrderStatusId(int id)
#region Status Changes
public void SetSubmitedStatus()
{
_orderStatusId = id;
_orderStatusId = OrderStatus.Submited.Id;
}
public void SetAwaitingValidationStatus()
{
if (_orderStatusId != OrderStatus.Submited.Id)
{
StatusChangeException();
}
_orderStatusId = OrderStatus.AwaitingValidation.Id;
AddDomainEvent(new OrderStatusChangedToAwaitingValidationDomainEvent(Id, OrderItems));
}
public void SetOrderStockConfirmed(IEnumerable<int> orderStockNotConfirmedItems = null)
public void SetStockConfirmedStatus(IEnumerable<int> orderStockNotConfirmedItems = null)
{
if(orderStockNotConfirmedItems is null)
if (_orderStatusId != OrderStatus.AwaitingValidation.Id)
{
OrderStatus = OrderStatus.StockValidated;
StatusChangeException();
}
if (orderStockNotConfirmedItems is null)
{
OrderStatus = OrderStatus.StockConfirmed;
_description = "All the items were confirmed with available stock.";
AddDomainEvent(new OrderStatusChangedToStockConfirmedDomainEvent(Id));
}
else
{
@ -117,10 +138,36 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
var itemsStockNotConfirmedDescription = string.Join(", ", itemsStockNotConfirmedProductNames);
_description = $"The product items don't have stock: ({itemsStockNotConfirmedDescription}).";
}
}
public void SetPaidStatus()
{
if (_orderStatusId != OrderStatus.StockConfirmed.Id)
{
StatusChangeException();
}
_orderStatusId = OrderStatus.Paid.Id;
_description = "The payment was performed at a simulated \"American Bank checking bank account endinf on XX35071\"";
AddDomainEvent(new OrderStatusChangedToPaidDomainEvent(Id, OrderItems));
}
public void SetShippedStatus()
{
if (_orderStatusId != OrderStatus.Paid.Id)
{
StatusChangeException();
}
AddDomainEvent(new OrderStockConfirmedDomainEvent(Id, OrderStatus));
_orderStatusId = OrderStatus.Shipped.Id;
_description = "";
//Call Domain Event
}
#endregion
private void AddOrderStartedDomainEvent(string userId, int cardTypeId, string cardNumber,
string cardSecurityNumber, string cardHolderName, DateTime cardExpiration)
{
@ -130,6 +177,11 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
this.AddDomainEvent(orderStartedDomainEvent);
}
private void StatusChangeException()
{
throw new OrderingDomainException("Not able to process order event. Reason: no valid order status change");
}
}
}

+ 2
- 2
src/Services/Ordering/Ordering.Domain/AggregatesModel/OrderAggregate/OrderStatus.cs View File

@ -12,7 +12,7 @@
{
public static OrderStatus Submited = new OrderStatus(1, nameof(Submited).ToLowerInvariant());
public static OrderStatus AwaitingValidation = new OrderStatus(2, nameof(AwaitingValidation).ToLowerInvariant());
public static OrderStatus StockValidated = new OrderStatus(3, nameof(StockValidated).ToLowerInvariant());
public static OrderStatus StockConfirmed = new OrderStatus(3, nameof(StockConfirmed).ToLowerInvariant());
public static OrderStatus Paid = new OrderStatus(4, nameof(Paid).ToLowerInvariant());
public static OrderStatus Shipped = new OrderStatus(5, nameof(Shipped).ToLowerInvariant());
public static OrderStatus Cancelled = new OrderStatus(6, nameof(Cancelled).ToLowerInvariant());
@ -27,7 +27,7 @@
}
public static IEnumerable<OrderStatus> List() =>
new[] { Submited, AwaitingValidation, StockValidated, Paid, Shipped, Cancelled };
new[] { Submited, AwaitingValidation, StockConfirmed, Paid, Shipped, Cancelled };
public static OrderStatus FromName(string name)
{


+ 23
- 0
src/Services/Ordering/Ordering.Domain/Events/OrderStatusChangedToAwaitingValidationDomainEvent.cs View File

@ -0,0 +1,23 @@
namespace Ordering.Domain.Events
{
using MediatR;
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
using System.Collections.Generic;
/// <summary>
/// Event used when the grace period order is confirmed
/// </summary>
public class OrderStatusChangedToAwaitingValidationDomainEvent
: IAsyncNotification
{
public int OrderId { get; }
public IEnumerable<OrderItem> OrderItems { get; }
public OrderStatusChangedToAwaitingValidationDomainEvent(int orderId,
IEnumerable<OrderItem> orderItems)
{
OrderId = orderId;
OrderItems = orderItems;
}
}
}

+ 23
- 0
src/Services/Ordering/Ordering.Domain/Events/OrderStatusChangedToPaidDomainEvent.cs View File

@ -0,0 +1,23 @@
namespace Ordering.Domain.Events
{
using MediatR;
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
using System.Collections.Generic;
/// <summary>
/// Event used when the order is paid
/// </summary>
public class OrderStatusChangedToPaidDomainEvent
: IAsyncNotification
{
public int OrderId { get; }
public IEnumerable<OrderItem> OrderItems { get; }
public OrderStatusChangedToPaidDomainEvent(int orderId,
IEnumerable<OrderItem> orderItems)
{
OrderId = orderId;
OrderItems = orderItems;
}
}
}

+ 16
- 0
src/Services/Ordering/Ordering.Domain/Events/OrderStatusChangedToStockConfirmedDomainEvent.cs View File

@ -0,0 +1,16 @@
namespace Ordering.Domain.Events
{
using MediatR;
/// <summary>
/// Event used when the order stock items are confirmed
/// </summary>
public class OrderStatusChangedToStockConfirmedDomainEvent
: IAsyncNotification
{
public int OrderId { get; }
public OrderStatusChangedToStockConfirmedDomainEvent(int orderId)
=> OrderId = orderId;
}
}

+ 0
- 24
src/Services/Ordering/Ordering.Domain/Events/OrderStockMethodVerifiedDomainEvent.cs View File

@ -1,24 +0,0 @@
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
namespace Ordering.Domain.Events
{
using MediatR;
using System.Collections.Generic;
/// <summary>
/// Event used when the order stock items are verified
/// </summary>
public class OrderStockConfirmedDomainEvent
: IAsyncNotification
{
public int OrderId { get; }
public OrderStatus OrderStatus { get; }
public OrderStockConfirmedDomainEvent(int orderId,
OrderStatus orderStatus)
{
OrderId = orderId;
OrderStatus = orderStatus;
}
}
}

Loading…
Cancel
Save