Merge d4cca7440eb3f94069bc97102be0f0262049ba02 into 4267d24a3d44bff953d29646d183adf0e797fc0e
This commit is contained in:
commit
e8b1ee8256
@ -26,20 +26,18 @@
|
|||||||
|
|
||||||
await policy.ExecuteAsync(async () =>
|
await policy.ExecuteAsync(async () =>
|
||||||
{
|
{
|
||||||
|
|
||||||
var useCustomizationData = settings.Value
|
var useCustomizationData = settings.Value
|
||||||
.UseCustomizationData;
|
.UseCustomizationData;
|
||||||
|
|
||||||
var contentRootPath = env.ContentRootPath;
|
var contentRootPath = env.ContentRootPath;
|
||||||
|
|
||||||
|
|
||||||
using (context)
|
using (context)
|
||||||
{
|
{
|
||||||
context.Database.Migrate();
|
context.Database.Migrate();
|
||||||
|
|
||||||
if (!context.CardTypes.Any())
|
if (!context.CardTypes.Any())
|
||||||
{
|
{
|
||||||
context.CardTypes.AddRange(useCustomizationData
|
await context.CardTypes.AddRangeAsync(useCustomizationData
|
||||||
? GetCardTypesFromFile(contentRootPath, logger)
|
? GetCardTypesFromFile(contentRootPath, logger)
|
||||||
: GetPredefinedCardTypes());
|
: GetPredefinedCardTypes());
|
||||||
|
|
||||||
@ -48,7 +46,7 @@
|
|||||||
|
|
||||||
if (!context.OrderStatus.Any())
|
if (!context.OrderStatus.Any())
|
||||||
{
|
{
|
||||||
context.OrderStatus.AddRange(useCustomizationData
|
await context.OrderStatus.AddRangeAsync(useCustomizationData
|
||||||
? GetOrderStatusFromFile(contentRootPath, logger)
|
? GetOrderStatusFromFile(contentRootPath, logger)
|
||||||
: GetPredefinedOrderStatus());
|
: GetPredefinedOrderStatus());
|
||||||
}
|
}
|
||||||
|
@ -7,16 +7,16 @@ using System.Linq;
|
|||||||
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate
|
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate
|
||||||
{
|
{
|
||||||
public class Buyer
|
public class Buyer
|
||||||
: Entity, IAggregateRoot
|
: Entity, IAggregateRoot
|
||||||
{
|
{
|
||||||
public string IdentityGuid { get; private set; }
|
public string IdentityGuid { get; private set; }
|
||||||
|
|
||||||
private List<PaymentMethod> _paymentMethods;
|
private List<PaymentMethod> _paymentMethods;
|
||||||
|
|
||||||
public IEnumerable<PaymentMethod> PaymentMethods => _paymentMethods.AsReadOnly();
|
public IEnumerable<PaymentMethod> PaymentMethods => _paymentMethods.AsReadOnly();
|
||||||
|
|
||||||
protected Buyer() {
|
protected Buyer()
|
||||||
|
{
|
||||||
_paymentMethods = new List<PaymentMethod>();
|
_paymentMethods = new List<PaymentMethod>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,8 +29,8 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.B
|
|||||||
int cardTypeId, string alias, string cardNumber,
|
int cardTypeId, string alias, string cardNumber,
|
||||||
string securityNumber, string cardHolderName, DateTime expiration, int orderId)
|
string securityNumber, string cardHolderName, DateTime expiration, int orderId)
|
||||||
{
|
{
|
||||||
var existingPayment = _paymentMethods.Where(p => p.IsEqualTo(cardTypeId, cardNumber, expiration))
|
var existingPayment = _paymentMethods
|
||||||
.SingleOrDefault();
|
.SingleOrDefault(p => p.IsEqualTo(cardTypeId, cardNumber, expiration));
|
||||||
|
|
||||||
if (existingPayment != null)
|
if (existingPayment != null)
|
||||||
{
|
{
|
||||||
|
@ -5,20 +5,18 @@ using System.Linq;
|
|||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate
|
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate
|
||||||
{
|
{
|
||||||
|
|
||||||
public class CardType
|
public class CardType
|
||||||
: Enumeration
|
: Enumeration
|
||||||
{
|
{
|
||||||
public static CardType Amex = new CardType(1, "Amex");
|
public static readonly CardType Amex = new CardType(1, "Amex");
|
||||||
public static CardType Visa = new CardType(2, "Visa");
|
public static readonly CardType Visa = new CardType(2, "Visa");
|
||||||
public static CardType MasterCard = new CardType(3, "MasterCard");
|
public static readonly CardType MasterCard = new CardType(3, "MasterCard");
|
||||||
|
|
||||||
protected CardType() { }
|
protected CardType() { }
|
||||||
|
|
||||||
public CardType(int id, string name)
|
public CardType(int id, string name)
|
||||||
: base(id, name)
|
: base(id, name)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IEnumerable<CardType> List()
|
public static IEnumerable<CardType> List()
|
||||||
@ -33,7 +31,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.B
|
|||||||
|
|
||||||
if (state == null)
|
if (state == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentException($"Possible values for CardType: {String.Join(",", List().Select(s => s.Name))}");
|
throw new ArgumentException($"Possible values for CardType: {string.Join(",", List().Select(s => s.Name))}");
|
||||||
}
|
}
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
|
@ -6,10 +6,11 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.B
|
|||||||
//This is just the RepositoryContracts or Interface defined at the Domain Layer
|
//This is just the RepositoryContracts or Interface defined at the Domain Layer
|
||||||
//as requisite for the Buyer Aggregate
|
//as requisite for the Buyer Aggregate
|
||||||
|
|
||||||
public interface IBuyerRepository : IRepository<Buyer>
|
public interface IBuyerRepository
|
||||||
|
: IRepository<Buyer>
|
||||||
{
|
{
|
||||||
Buyer Add(Buyer buyer);
|
Buyer Add(Buyer buyer);
|
||||||
Buyer Update(Buyer buyer);
|
Buyer Update(Buyer buyer);
|
||||||
Task<Buyer> FindAsync(string BuyerIdentityGuid);
|
Task<Buyer> FindAsync(string buyerIdentityGuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.B
|
|||||||
|
|
||||||
public PaymentMethod(int cardTypeId, string alias, string cardNumber, string securityNumber, string cardHolderName, DateTime expiration)
|
public PaymentMethod(int cardTypeId, string alias, string cardNumber, string securityNumber, string cardHolderName, DateTime expiration)
|
||||||
{
|
{
|
||||||
|
|
||||||
_cardNumber = !string.IsNullOrWhiteSpace(cardNumber) ? cardNumber : throw new OrderingDomainException(nameof(cardNumber));
|
_cardNumber = !string.IsNullOrWhiteSpace(cardNumber) ? cardNumber : throw new OrderingDomainException(nameof(cardNumber));
|
||||||
_securityNumber = !string.IsNullOrWhiteSpace(securityNumber) ? securityNumber : throw new OrderingDomainException(nameof(securityNumber));
|
_securityNumber = !string.IsNullOrWhiteSpace(securityNumber) ? securityNumber : throw new OrderingDomainException(nameof(securityNumber));
|
||||||
_cardHolderName = !string.IsNullOrWhiteSpace(cardHolderName) ? cardHolderName : throw new OrderingDomainException(nameof(cardHolderName));
|
_cardHolderName = !string.IsNullOrWhiteSpace(cardHolderName) ? cardHolderName : throw new OrderingDomainException(nameof(cardHolderName));
|
||||||
|
@ -4,7 +4,8 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate
|
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate
|
||||||
{
|
{
|
||||||
public class Address : ValueObject
|
public class Address
|
||||||
|
: ValueObject
|
||||||
{
|
{
|
||||||
public String Street { get; private set; }
|
public String Street { get; private set; }
|
||||||
public String City { get; private set; }
|
public String City { get; private set; }
|
||||||
|
@ -6,12 +6,11 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
|||||||
//This is just the RepositoryContracts or Interface defined at the Domain Layer
|
//This is just the RepositoryContracts or Interface defined at the Domain Layer
|
||||||
//as requisite for the Order Aggregate
|
//as requisite for the Order Aggregate
|
||||||
|
|
||||||
public interface IOrderRepository : IRepository<Order>
|
public interface IOrderRepository
|
||||||
|
: IRepository<Order>
|
||||||
{
|
{
|
||||||
Order Add(Order order);
|
Order Add(Order order);
|
||||||
|
|
||||||
void Update(Order order);
|
void Update(Order order);
|
||||||
|
|
||||||
Task<Order> GetAsync(int orderId);
|
Task<Order> GetAsync(int orderId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,10 +34,13 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
|||||||
|
|
||||||
private int? _paymentMethodId;
|
private int? _paymentMethodId;
|
||||||
|
|
||||||
protected Order() { _orderItems = new List<OrderItem>(); }
|
protected Order()
|
||||||
|
{
|
||||||
|
_orderItems = new List<OrderItem>();
|
||||||
|
}
|
||||||
|
|
||||||
public Order(string userId, Address address, int cardTypeId, string cardNumber, string cardSecurityNumber,
|
public Order(string userId, Address address, int cardTypeId, string cardNumber, string cardSecurityNumber,
|
||||||
string cardHolderName, DateTime cardExpiration, int? buyerId = null, int? paymentMethodId = null)
|
string cardHolderName, DateTime cardExpiration, int? buyerId = null, int? paymentMethodId = null)
|
||||||
{
|
{
|
||||||
_orderItems = new List<OrderItem>();
|
_orderItems = new List<OrderItem>();
|
||||||
_buyerId = buyerId;
|
_buyerId = buyerId;
|
||||||
@ -58,8 +61,8 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
|||||||
// in order to maintain consistency between the whole Aggregate.
|
// in order to maintain consistency between the whole Aggregate.
|
||||||
public void AddOrderItem(int productId, string productName, decimal unitPrice, decimal discount, string pictureUrl, int units = 1)
|
public void AddOrderItem(int productId, string productName, decimal unitPrice, decimal discount, string pictureUrl, int units = 1)
|
||||||
{
|
{
|
||||||
var existingOrderForProduct = _orderItems.Where(o => o.ProductId == productId)
|
var existingOrderForProduct = _orderItems
|
||||||
.SingleOrDefault();
|
.SingleOrDefault(o => o.ProductId == productId);
|
||||||
|
|
||||||
if (existingOrderForProduct != null)
|
if (existingOrderForProduct != null)
|
||||||
{
|
{
|
||||||
@ -92,12 +95,12 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void SetAwaitingValidationStatus()
|
public void SetAwaitingValidationStatus()
|
||||||
{
|
{
|
||||||
if (_orderStatusId == OrderStatus.Submitted.Id)
|
if (_orderStatusId == OrderStatus.Submitted.Id)
|
||||||
{
|
{
|
||||||
AddDomainEvent(new OrderStatusChangedToAwaitingValidationDomainEvent(Id, _orderItems));
|
AddDomainEvent(new OrderStatusChangedToAwaitingValidationDomainEvent(Id, _orderItems));
|
||||||
_orderStatusId = OrderStatus.AwaitingValidation.Id;
|
_orderStatusId = OrderStatus.AwaitingValidation.Id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetStockConfirmedStatus()
|
public void SetStockConfirmedStatus()
|
||||||
@ -157,11 +160,11 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
|||||||
|
|
||||||
var itemsStockRejectedDescription = string.Join(", ", itemsStockRejectedProductNames);
|
var itemsStockRejectedDescription = string.Join(", ", itemsStockRejectedProductNames);
|
||||||
_description = $"The product items don't have stock: ({itemsStockRejectedDescription}).";
|
_description = $"The product items don't have stock: ({itemsStockRejectedDescription}).";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddOrderStartedDomainEvent(string userId, int cardTypeId, string cardNumber,
|
private void AddOrderStartedDomainEvent(string userId, int cardTypeId, string cardNumber,
|
||||||
string cardSecurityNumber, string cardHolderName, DateTime cardExpiration)
|
string cardSecurityNumber, string cardHolderName, DateTime cardExpiration)
|
||||||
{
|
{
|
||||||
var orderStartedDomainEvent = new OrderStartedDomainEvent(this, userId, cardTypeId,
|
var orderStartedDomainEvent = new OrderStartedDomainEvent(this, userId, cardTypeId,
|
||||||
cardNumber, cardSecurityNumber,
|
cardNumber, cardSecurityNumber,
|
||||||
@ -180,5 +183,4 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
|||||||
return _orderItems.Sum(o => o.GetUnits() * o.GetUnitPrice());
|
return _orderItems.Sum(o => o.GetUnits() * o.GetUnitPrice());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,5 @@
|
|||||||
using Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork;
|
using Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork;
|
||||||
using Ordering.Domain.Exceptions;
|
using Ordering.Domain.Exceptions;
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate
|
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate
|
||||||
{
|
{
|
||||||
@ -20,7 +19,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
|||||||
|
|
||||||
protected OrderItem() { }
|
protected OrderItem() { }
|
||||||
|
|
||||||
public OrderItem(int productId, string productName, decimal unitPrice, decimal discount, string PictureUrl, int units = 1)
|
public OrderItem(int productId, string productName, decimal unitPrice, decimal discount, string pictureUrl, int units = 1)
|
||||||
{
|
{
|
||||||
if (units <= 0)
|
if (units <= 0)
|
||||||
{
|
{
|
||||||
@ -38,12 +37,12 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
|||||||
_unitPrice = unitPrice;
|
_unitPrice = unitPrice;
|
||||||
_discount = discount;
|
_discount = discount;
|
||||||
_units = units;
|
_units = units;
|
||||||
_pictureUrl = PictureUrl;
|
_pictureUrl = pictureUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetPictureUri(string pictureUri)
|
public void SetPictureUri(string pictureUri)
|
||||||
{
|
{
|
||||||
if (!String.IsNullOrWhiteSpace(pictureUri))
|
if (!string.IsNullOrWhiteSpace(pictureUri))
|
||||||
{
|
{
|
||||||
_pictureUrl = pictureUri;
|
_pictureUrl = pictureUri;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate
|
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate
|
||||||
{
|
{
|
||||||
using global::Ordering.Domain.Exceptions;
|
using global::Ordering.Domain.Exceptions;
|
||||||
using Seedwork;
|
|
||||||
using SeedWork;
|
using SeedWork;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -17,9 +16,7 @@
|
|||||||
public static OrderStatus Shipped = new OrderStatus(5, nameof(Shipped).ToLowerInvariant());
|
public static OrderStatus Shipped = new OrderStatus(5, nameof(Shipped).ToLowerInvariant());
|
||||||
public static OrderStatus Cancelled = new OrderStatus(6, nameof(Cancelled).ToLowerInvariant());
|
public static OrderStatus Cancelled = new OrderStatus(6, nameof(Cancelled).ToLowerInvariant());
|
||||||
|
|
||||||
protected OrderStatus()
|
protected OrderStatus() { }
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public OrderStatus(int id, string name)
|
public OrderStatus(int id, string name)
|
||||||
: base(id, name)
|
: base(id, name)
|
||||||
@ -32,11 +29,11 @@
|
|||||||
public static OrderStatus FromName(string name)
|
public static OrderStatus FromName(string name)
|
||||||
{
|
{
|
||||||
var state = List()
|
var state = List()
|
||||||
.SingleOrDefault(s => String.Equals(s.Name, name, StringComparison.CurrentCultureIgnoreCase));
|
.SingleOrDefault(s => string.Equals(s.Name, name, StringComparison.CurrentCultureIgnoreCase));
|
||||||
|
|
||||||
if (state == null)
|
if (state == null)
|
||||||
{
|
{
|
||||||
throw new OrderingDomainException($"Possible values for OrderStatus: {String.Join(",", List().Select(s => s.Name))}");
|
throw new OrderingDomainException($"Possible values for OrderStatus: {string.Join(",", List().Select(s => s.Name))}");
|
||||||
}
|
}
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
@ -48,7 +45,7 @@
|
|||||||
|
|
||||||
if (state == null)
|
if (state == null)
|
||||||
{
|
{
|
||||||
throw new OrderingDomainException($"Possible values for OrderStatus: {String.Join(",", List().Select(s => s.Name))}");
|
throw new OrderingDomainException($"Possible values for OrderStatus: {string.Join(",", List().Select(s => s.Name))}");
|
||||||
}
|
}
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
using MediatR;
|
using MediatR;
|
||||||
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
|
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace Ordering.Domain.Events
|
namespace Ordering.Domain.Events
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Event used when an order is created
|
/// Event used when an order is created
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class OrderStartedDomainEvent : INotification
|
public class OrderStartedDomainEvent
|
||||||
|
: INotification
|
||||||
{
|
{
|
||||||
public string UserId { get; private set; }
|
public string UserId { get; private set; }
|
||||||
public int CardTypeId { get; private set; }
|
public int CardTypeId { get; private set; }
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace Ordering.Domain.Exceptions
|
namespace Ordering.Domain.Exceptions
|
||||||
{
|
{
|
||||||
|
@ -1,33 +1,27 @@
|
|||||||
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork
|
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork
|
||||||
{
|
{
|
||||||
using System;
|
|
||||||
using MediatR;
|
using MediatR;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
public abstract class Entity
|
public abstract class Entity
|
||||||
{
|
{
|
||||||
int? _requestedHashCode;
|
int? _requestedHashCode;
|
||||||
int _Id;
|
int _Id;
|
||||||
public virtual int Id
|
public virtual int Id
|
||||||
{
|
{
|
||||||
get
|
get => _Id;
|
||||||
{
|
protected set => _Id = value;
|
||||||
return _Id;
|
|
||||||
}
|
|
||||||
protected set
|
|
||||||
{
|
|
||||||
_Id = value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<INotification> _domainEvents;
|
private List<INotification> _domainEvents;
|
||||||
public List<INotification> DomainEvents => _domainEvents;
|
public List<INotification> DomainEvents => _domainEvents;
|
||||||
|
|
||||||
public void AddDomainEvent(INotification eventItem)
|
public void AddDomainEvent(INotification eventItem)
|
||||||
{
|
{
|
||||||
_domainEvents = _domainEvents ?? new List<INotification>();
|
_domainEvents = _domainEvents ?? new List<INotification>();
|
||||||
_domainEvents.Add(eventItem);
|
_domainEvents.Add(eventItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveDomainEvent(INotification eventItem)
|
public void RemoveDomainEvent(INotification eventItem)
|
||||||
{
|
{
|
||||||
if (_domainEvents is null) return;
|
if (_domainEvents is null) return;
|
||||||
@ -36,15 +30,15 @@
|
|||||||
|
|
||||||
public bool IsTransient()
|
public bool IsTransient()
|
||||||
{
|
{
|
||||||
return this.Id == default(Int32);
|
return this.Id == default(int);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Equals(object obj)
|
public override bool Equals(object obj)
|
||||||
{
|
{
|
||||||
if (obj == null || !(obj is Entity))
|
if (!(obj is Entity))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (Object.ReferenceEquals(this, obj))
|
if (object.ReferenceEquals(this, obj))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (this.GetType() != obj.GetType())
|
if (this.GetType() != obj.GetType())
|
||||||
@ -53,9 +47,13 @@
|
|||||||
Entity item = (Entity)obj;
|
Entity item = (Entity)obj;
|
||||||
|
|
||||||
if (item.IsTransient() || this.IsTransient())
|
if (item.IsTransient() || this.IsTransient())
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
return item.Id == this.Id;
|
return item.Id == this.Id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int GetHashCode()
|
public override int GetHashCode()
|
||||||
@ -63,20 +61,27 @@
|
|||||||
if (!IsTransient())
|
if (!IsTransient())
|
||||||
{
|
{
|
||||||
if (!_requestedHashCode.HasValue)
|
if (!_requestedHashCode.HasValue)
|
||||||
|
{
|
||||||
_requestedHashCode = this.Id.GetHashCode() ^ 31; // XOR for random distribution (http://blogs.msdn.com/b/ericlippert/archive/2011/02/28/guidelines-and-rules-for-gethashcode.aspx)
|
_requestedHashCode = this.Id.GetHashCode() ^ 31; // XOR for random distribution (http://blogs.msdn.com/b/ericlippert/archive/2011/02/28/guidelines-and-rules-for-gethashcode.aspx)
|
||||||
|
}
|
||||||
|
|
||||||
return _requestedHashCode.Value;
|
return _requestedHashCode.Value;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
return base.GetHashCode();
|
return base.GetHashCode();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public static bool operator ==(Entity left, Entity right)
|
public static bool operator ==(Entity left, Entity right)
|
||||||
{
|
{
|
||||||
if (Object.Equals(left, null))
|
if (object.Equals(left, null))
|
||||||
return (Object.Equals(right, null)) ? true : false;
|
{
|
||||||
|
return object.Equals(right, null);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
return left.Equals(right);
|
return left.Equals(right);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool operator !=(Entity left, Entity right)
|
public static bool operator !=(Entity left, Entity right)
|
||||||
|
@ -5,15 +5,14 @@ using System.Reflection;
|
|||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork
|
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork
|
||||||
{
|
{
|
||||||
public abstract class Enumeration : IComparable
|
public abstract class Enumeration
|
||||||
|
: IComparable
|
||||||
{
|
{
|
||||||
public string Name { get; private set; }
|
public string Name { get; private set; }
|
||||||
|
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
|
||||||
protected Enumeration()
|
protected Enumeration() { }
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Enumeration(int id, string name)
|
protected Enumeration(int id, string name)
|
||||||
{
|
{
|
||||||
@ -34,9 +33,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork
|
|||||||
foreach (var info in fields)
|
foreach (var info in fields)
|
||||||
{
|
{
|
||||||
var instance = new T();
|
var instance = new T();
|
||||||
var locatedValue = info.GetValue(instance) as T;
|
if (info.GetValue(instance) is T locatedValue)
|
||||||
|
|
||||||
if (locatedValue != null)
|
|
||||||
{
|
{
|
||||||
yield return locatedValue;
|
yield return locatedValue;
|
||||||
}
|
}
|
||||||
@ -45,9 +42,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork
|
|||||||
|
|
||||||
public override bool Equals(object obj)
|
public override bool Equals(object obj)
|
||||||
{
|
{
|
||||||
var otherValue = obj as Enumeration;
|
if (!(obj is Enumeration otherValue))
|
||||||
|
|
||||||
if (otherValue == null)
|
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork
|
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork
|
||||||
{
|
{
|
||||||
|
|
||||||
public interface IAggregateRoot { }
|
public interface IAggregateRoot { }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,9 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork
|
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork
|
||||||
{
|
{
|
||||||
public interface IUnitOfWork : IDisposable
|
public interface IUnitOfWork
|
||||||
{
|
: IDisposable
|
||||||
|
{
|
||||||
Task<int> SaveChangesAsync(CancellationToken cancellationToken = default(CancellationToken));
|
Task<int> SaveChangesAsync(CancellationToken cancellationToken = default(CancellationToken));
|
||||||
Task<bool> SaveEntitiesAsync(CancellationToken cancellationToken = default(CancellationToken));
|
Task<bool> SaveEntitiesAsync(CancellationToken cancellationToken = default(CancellationToken));
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ValueObject other = (ValueObject)obj;
|
ValueObject other = (ValueObject)obj;
|
||||||
IEnumerator<object> thisValues = GetAtomicValues().GetEnumerator();
|
IEnumerator<object> thisValues = GetAtomicValues().GetEnumerator();
|
||||||
IEnumerator<object> otherValues = other.GetAtomicValues().GetEnumerator();
|
IEnumerator<object> otherValues = other.GetAtomicValues().GetEnumerator();
|
||||||
|
@ -24,7 +24,7 @@ namespace Ordering.Infrastructure.EntityConfigurations
|
|||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
buyerConfiguration.HasIndex("IdentityGuid")
|
buyerConfiguration.HasIndex("IdentityGuid")
|
||||||
.IsUnique(true);
|
.IsUnique();
|
||||||
|
|
||||||
buyerConfiguration.HasMany(b => b.PaymentMethods)
|
buyerConfiguration.HasMany(b => b.PaymentMethods)
|
||||||
.WithOne()
|
.WithOne()
|
||||||
|
@ -4,7 +4,8 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Idempotency
|
namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Idempotency
|
||||||
{
|
{
|
||||||
public class RequestManager : IRequestManager
|
public class RequestManager
|
||||||
|
: IRequestManager
|
||||||
{
|
{
|
||||||
private readonly OrderingContext _context;
|
private readonly OrderingContext _context;
|
||||||
|
|
||||||
|
@ -12,7 +12,8 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure
|
namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure
|
||||||
{
|
{
|
||||||
public class OrderingContext : DbContext, IUnitOfWork
|
public class OrderingContext
|
||||||
|
: DbContext, IUnitOfWork
|
||||||
{
|
{
|
||||||
public const string DEFAULT_SCHEMA = "ordering";
|
public const string DEFAULT_SCHEMA = "ordering";
|
||||||
public DbSet<Order> Orders { get; set; }
|
public DbSet<Order> Orders { get; set; }
|
||||||
@ -24,13 +25,14 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure
|
|||||||
|
|
||||||
private readonly IMediator _mediator;
|
private readonly IMediator _mediator;
|
||||||
|
|
||||||
private OrderingContext(DbContextOptions<OrderingContext> options) : base (options) { }
|
private OrderingContext(DbContextOptions<OrderingContext> options)
|
||||||
|
: base (options) { }
|
||||||
|
|
||||||
public OrderingContext(DbContextOptions<OrderingContext> options, IMediator mediator) : base(options)
|
public OrderingContext(DbContextOptions<OrderingContext> options, IMediator mediator)
|
||||||
|
: base(options)
|
||||||
{
|
{
|
||||||
_mediator = mediator ?? throw new ArgumentNullException(nameof(mediator));
|
_mediator = mediator ?? throw new ArgumentNullException(nameof(mediator));
|
||||||
|
|
||||||
|
|
||||||
System.Diagnostics.Debug.WriteLine("OrderingContext::ctor ->" + this.GetHashCode());
|
System.Diagnostics.Debug.WriteLine("OrderingContext::ctor ->" + this.GetHashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,13 +59,14 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure
|
|||||||
|
|
||||||
// After executing this line all the changes (from the Command Handler and Domain Event Handlers)
|
// After executing this line all the changes (from the Command Handler and Domain Event Handlers)
|
||||||
// performed throught the DbContext will be commited
|
// performed throught the DbContext will be commited
|
||||||
var result = await base.SaveChangesAsync();
|
var result = await base.SaveChangesAsync(cancellationToken);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class OrderingContextDesignFactory : IDesignTimeDbContextFactory<OrderingContext>
|
public class OrderingContextDesignFactory
|
||||||
|
: IDesignTimeDbContextFactory<OrderingContext>
|
||||||
{
|
{
|
||||||
public OrderingContext CreateDbContext(string[] args)
|
public OrderingContext CreateDbContext(string[] args)
|
||||||
{
|
{
|
||||||
@ -73,9 +76,11 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure
|
|||||||
return new OrderingContext(optionsBuilder.Options,new NoMediator());
|
return new OrderingContext(optionsBuilder.Options,new NoMediator());
|
||||||
}
|
}
|
||||||
|
|
||||||
class NoMediator : IMediator
|
class NoMediator
|
||||||
|
: IMediator
|
||||||
{
|
{
|
||||||
public Task Publish<TNotification>(TNotification notification, CancellationToken cancellationToken = default(CancellationToken)) where TNotification : INotification
|
public Task Publish<TNotification>(TNotification notification, CancellationToken cancellationToken = default(CancellationToken))
|
||||||
|
where TNotification : INotification
|
||||||
{
|
{
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
@ -11,13 +11,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositor
|
|||||||
: IBuyerRepository
|
: IBuyerRepository
|
||||||
{
|
{
|
||||||
private readonly OrderingContext _context;
|
private readonly OrderingContext _context;
|
||||||
public IUnitOfWork UnitOfWork
|
public IUnitOfWork UnitOfWork => _context;
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return _context;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public BuyerRepository(OrderingContext context)
|
public BuyerRepository(OrderingContext context)
|
||||||
{
|
{
|
||||||
@ -35,14 +29,14 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositor
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
return buyer;
|
return buyer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Buyer Update(Buyer buyer)
|
public Buyer Update(Buyer buyer)
|
||||||
{
|
{
|
||||||
return _context.Buyers
|
return _context.Buyers
|
||||||
.Update(buyer)
|
.Update(buyer)
|
||||||
.Entity;
|
.Entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Buyer> FindAsync(string identity)
|
public async Task<Buyer> FindAsync(string identity)
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
|
using Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate;
|
||||||
using Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork;
|
using Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork;
|
||||||
using Ordering.Domain.Exceptions;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -12,13 +11,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Repositor
|
|||||||
{
|
{
|
||||||
private readonly OrderingContext _context;
|
private readonly OrderingContext _context;
|
||||||
|
|
||||||
public IUnitOfWork UnitOfWork
|
public IUnitOfWork UnitOfWork => _context;
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return _context;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public OrderRepository(OrderingContext context)
|
public OrderRepository(OrderingContext context)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user