2017-01-25 17:10:08 +01:00
|
|
|
|
using Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork;
|
|
|
|
|
using System;
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
public string FullName { get; private set; }
|
|
|
|
|
|
2017-01-25 17:10:08 +01:00
|
|
|
|
private HashSet<Payment> _payments;
|
|
|
|
|
|
|
|
|
|
public IEnumerable<Payment> Payments => _payments?.ToList().AsEnumerable();
|
2016-11-24 14:59:25 +01:00
|
|
|
|
|
2016-11-21 12:41:36 +01:00
|
|
|
|
protected Buyer() { }
|
2016-11-24 14:59:25 +01:00
|
|
|
|
|
2017-01-25 17:10:08 +01:00
|
|
|
|
public Buyer(string identity)
|
|
|
|
|
{
|
|
|
|
|
if (String.IsNullOrWhiteSpace(identity))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException(nameof(identity));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FullName = identity;
|
|
|
|
|
|
|
|
|
|
_payments = new HashSet<Payment>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Payment AddPayment(int cardTypeId, string alias, string cardNumber, string securityNumber, string cardHolderName, DateTime expiration)
|
2016-11-24 14:59:25 +01:00
|
|
|
|
{
|
2017-01-25 17:10:08 +01:00
|
|
|
|
var existingPayment = Payments.Where(p => p.IsEqualTo(cardTypeId, cardNumber, expiration))
|
|
|
|
|
.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
|
|
|
|
|
{
|
|
|
|
|
var payment = new Payment(cardTypeId, alias, cardNumber, securityNumber, cardHolderName, expiration);
|
|
|
|
|
|
|
|
|
|
_payments.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
|
|
|
|
}
|
|
|
|
|
}
|