2017-01-30 15:46:43 +01:00
|
|
|
|
using Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork;
|
2017-01-25 17:10:08 +01:00
|
|
|
|
using System;
|
2017-02-14 16:17:30 +01:00
|
|
|
|
using System.Collections;
|
2017-01-25 17:10:08 +01:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2016-11-21 12:41:36 +01:00
|
|
|
|
|
2017-01-25 17:10:08 +01:00
|
|
|
|
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.BuyerAggregate
|
|
|
|
|
{
|
2016-11-21 12:41:36 +01:00
|
|
|
|
public class Buyer
|
2017-01-25 17:10:08 +01:00
|
|
|
|
: Entity, IAggregateRoot
|
2016-11-21 12:41:36 +01:00
|
|
|
|
{
|
2017-02-07 23:03:35 -08:00
|
|
|
|
public string IdentityGuid { get; private set; }
|
2016-11-21 12:41:36 +01:00
|
|
|
|
|
2017-02-02 17:30:15 -08:00
|
|
|
|
private List<PaymentMethod> _paymentMethods;
|
2017-01-25 17:10:08 +01:00
|
|
|
|
|
2017-02-14 16:17:30 +01:00
|
|
|
|
public IEnumerable<PaymentMethod> PaymentMethods => _paymentMethods.AsReadOnly();
|
2016-11-24 14:59:25 +01:00
|
|
|
|
|
2017-02-14 16:17:30 +01:00
|
|
|
|
protected Buyer() {
|
|
|
|
|
_paymentMethods = new List<PaymentMethod>();
|
|
|
|
|
}
|
2016-11-24 14:59:25 +01:00
|
|
|
|
|
2017-02-14 16:17:30 +01:00
|
|
|
|
public Buyer(string identity) : this()
|
2017-01-25 17:10:08 +01:00
|
|
|
|
{
|
|
|
|
|
if (String.IsNullOrWhiteSpace(identity))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException(nameof(identity));
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-07 23:03:35 -08:00
|
|
|
|
IdentityGuid = identity;
|
2017-01-25 17:10:08 +01:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-27 11:38:23 +01:00
|
|
|
|
public PaymentMethod AddPaymentMethod(int cardTypeId, string alias, string cardNumber, string securityNumber, string cardHolderName, DateTime expiration)
|
2016-11-24 14:59:25 +01:00
|
|
|
|
{
|
2017-01-27 11:38:23 +01:00
|
|
|
|
var existingPayment = _paymentMethods.Where(p => p.IsEqualTo(cardTypeId, cardNumber, expiration))
|
2017-01-25 17:10:08 +01:00
|
|
|
|
.SingleOrDefault();
|
|
|
|
|
|
|
|
|
|
if (existingPayment != null)
|
2016-11-24 14:59:25 +01:00
|
|
|
|
{
|
2017-01-25 17:10:08 +01:00
|
|
|
|
return existingPayment;
|
2016-11-24 14:59:25 +01:00
|
|
|
|
}
|
2017-01-25 17:10:08 +01:00
|
|
|
|
else
|
|
|
|
|
{
|
2017-01-27 11:38:23 +01:00
|
|
|
|
var payment = new PaymentMethod(cardTypeId, alias, cardNumber, securityNumber, cardHolderName, expiration);
|
2017-01-25 17:10:08 +01:00
|
|
|
|
|
2017-01-27 11:38:23 +01:00
|
|
|
|
_paymentMethods.Add(payment);
|
2016-11-24 14:59:25 +01:00
|
|
|
|
|
2017-01-25 17:10:08 +01:00
|
|
|
|
return payment;
|
|
|
|
|
}
|
2016-11-24 14:59:25 +01:00
|
|
|
|
}
|
2016-11-21 12:41:36 +01:00
|
|
|
|
}
|
|
|
|
|
}
|