2017-01-17 18:32:40 -08:00
|
|
|
|
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate
|
2016-11-21 12:41:36 +01:00
|
|
|
|
{
|
2017-03-27 14:05:28 +02:00
|
|
|
|
using global::Ordering.Domain.Exceptions;
|
2017-01-30 15:46:43 +01:00
|
|
|
|
using Seedwork;
|
2017-02-23 13:57:36 +01:00
|
|
|
|
using SeedWork;
|
2016-11-21 12:41:36 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
public class OrderStatus
|
2017-02-23 13:57:36 +01:00
|
|
|
|
: Enumeration
|
2016-11-21 12:41:36 +01:00
|
|
|
|
{
|
2017-05-09 13:58:48 +02:00
|
|
|
|
public static OrderStatus Submited = new OrderStatus(1, nameof(Submited).ToLowerInvariant());
|
|
|
|
|
public static OrderStatus AwaitingValidation = new OrderStatus(2, nameof(AwaitingValidation).ToLowerInvariant());
|
2017-05-15 19:17:16 +02:00
|
|
|
|
public static OrderStatus StockConfirmed = new OrderStatus(3, nameof(StockConfirmed).ToLowerInvariant());
|
2017-05-09 13:58:48 +02:00
|
|
|
|
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());
|
2016-11-21 12:41:36 +01:00
|
|
|
|
|
|
|
|
|
protected OrderStatus()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public OrderStatus(int id, string name)
|
2017-02-23 13:57:36 +01:00
|
|
|
|
: base(id, name)
|
2016-11-21 12:41:36 +01:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-09 13:58:48 +02:00
|
|
|
|
public static IEnumerable<OrderStatus> List() =>
|
2017-05-15 19:17:16 +02:00
|
|
|
|
new[] { Submited, AwaitingValidation, StockConfirmed, Paid, Shipped, Cancelled };
|
2016-11-21 12:41:36 +01:00
|
|
|
|
|
|
|
|
|
public static OrderStatus FromName(string name)
|
|
|
|
|
{
|
|
|
|
|
var state = List()
|
|
|
|
|
.SingleOrDefault(s => String.Equals(s.Name, name, StringComparison.CurrentCultureIgnoreCase));
|
|
|
|
|
|
|
|
|
|
if (state == null)
|
|
|
|
|
{
|
2017-03-27 14:05:28 +02:00
|
|
|
|
throw new OrderingDomainException($"Possible values for OrderStatus: {String.Join(",", List().Select(s => s.Name))}");
|
2016-11-21 12:41:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static OrderStatus From(int id)
|
|
|
|
|
{
|
|
|
|
|
var state = List().SingleOrDefault(s => s.Id == id);
|
|
|
|
|
|
|
|
|
|
if (state == null)
|
|
|
|
|
{
|
2017-03-27 14:05:28 +02:00
|
|
|
|
throw new OrderingDomainException($"Possible values for OrderStatus: {String.Join(",", List().Select(s => s.Name))}");
|
2016-11-21 12:41:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|