2017-01-25 17:10:08 +01:00
|
|
|
|
using Microsoft.eShopOnContainers.Services.Ordering.Domain.SeedWork;
|
|
|
|
|
using System;
|
2016-11-21 12:41:36 +01:00
|
|
|
|
|
2017-01-25 17:10:08 +01:00
|
|
|
|
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate
|
|
|
|
|
{
|
2016-11-21 12:41:36 +01:00
|
|
|
|
public class OrderItem
|
2017-01-25 17:10:08 +01:00
|
|
|
|
: Entity
|
2016-11-21 12:41:36 +01:00
|
|
|
|
{
|
2017-01-25 17:10:08 +01:00
|
|
|
|
private string _productName;
|
|
|
|
|
private string _pictureUrl;
|
|
|
|
|
private int _orderId;
|
|
|
|
|
private decimal _unitPrice;
|
|
|
|
|
private decimal _discount;
|
|
|
|
|
private int _units;
|
|
|
|
|
|
|
|
|
|
public int ProductId { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected OrderItem() { }
|
|
|
|
|
|
|
|
|
|
public OrderItem(int productId, string productName, decimal unitPrice, decimal discount, int units = 1)
|
|
|
|
|
{
|
|
|
|
|
if (units <= 0)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("Invalid number of units");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((unitPrice * units) < discount)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException("The total of order item is lower than applied discount");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProductId = productId;
|
2016-11-21 12:41:36 +01:00
|
|
|
|
|
2017-01-25 17:10:08 +01:00
|
|
|
|
_productName = productName;
|
|
|
|
|
_unitPrice = unitPrice;
|
|
|
|
|
_discount = discount;
|
|
|
|
|
_units = units;
|
|
|
|
|
}
|
2016-11-21 12:41:36 +01:00
|
|
|
|
|
2017-01-25 17:10:08 +01:00
|
|
|
|
public void SetPictureUri(string pictureUri)
|
|
|
|
|
{
|
|
|
|
|
if (!String.IsNullOrWhiteSpace(pictureUri))
|
|
|
|
|
{
|
|
|
|
|
_pictureUrl = pictureUri;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-17 14:41:16 +01:00
|
|
|
|
|
2017-01-25 17:10:08 +01:00
|
|
|
|
public decimal GetCurrentDiscount()
|
|
|
|
|
{
|
|
|
|
|
return _discount;
|
|
|
|
|
}
|
2016-11-21 12:41:36 +01:00
|
|
|
|
|
2017-01-25 17:10:08 +01:00
|
|
|
|
public void SetNewDiscount(decimal discount)
|
|
|
|
|
{
|
|
|
|
|
if (discount < 0)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException("Discount is not valid");
|
|
|
|
|
}
|
2016-11-21 12:41:36 +01:00
|
|
|
|
|
2017-01-25 17:10:08 +01:00
|
|
|
|
_discount = discount;
|
|
|
|
|
}
|
2016-11-21 12:41:36 +01:00
|
|
|
|
|
2017-01-25 17:10:08 +01:00
|
|
|
|
public void AddUnits(int units)
|
|
|
|
|
{
|
|
|
|
|
if (units < 0)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException("Invalid units");
|
|
|
|
|
}
|
2016-11-21 12:41:36 +01:00
|
|
|
|
|
2017-01-25 17:10:08 +01:00
|
|
|
|
_units += units;
|
|
|
|
|
}
|
2016-11-21 12:41:36 +01:00
|
|
|
|
}
|
|
|
|
|
}
|