make fields readonly
This commit is contained in:
parent
4c530da377
commit
99d47401c0
@ -7,13 +7,13 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.B
|
|||||||
public class PaymentMethod
|
public class PaymentMethod
|
||||||
: Entity
|
: Entity
|
||||||
{
|
{
|
||||||
private string _alias;
|
private readonly string _alias;
|
||||||
private string _cardNumber;
|
private readonly string _cardNumber;
|
||||||
private string _securityNumber;
|
private readonly string _securityNumber;
|
||||||
private string _cardHolderName;
|
private readonly string _cardHolderName;
|
||||||
private DateTime _expiration;
|
private readonly DateTime _expiration;
|
||||||
|
|
||||||
private int _cardTypeId;
|
private readonly int _cardTypeId;
|
||||||
public CardType CardType { get; private set; }
|
public CardType CardType { get; private set; }
|
||||||
|
|
||||||
|
|
||||||
@ -37,10 +37,8 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.B
|
|||||||
}
|
}
|
||||||
|
|
||||||
public bool IsEqualTo(int cardTypeId, string cardNumber, DateTime expiration)
|
public bool IsEqualTo(int cardTypeId, string cardNumber, DateTime expiration)
|
||||||
{
|
=> _cardTypeId == cardTypeId
|
||||||
return _cardTypeId == cardTypeId
|
|
||||||
&& _cardNumber == cardNumber
|
&& _cardNumber == cardNumber
|
||||||
&& _expiration == expiration;
|
&& _expiration == expiration;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -13,7 +13,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
|||||||
// DDD Patterns comment
|
// DDD Patterns comment
|
||||||
// Using private fields, allowed since EF Core 1.1, is a much better encapsulation
|
// Using private fields, allowed since EF Core 1.1, is a much better encapsulation
|
||||||
// aligned with DDD Aggregates and Domain Entities (Instead of properties and property collections)
|
// aligned with DDD Aggregates and Domain Entities (Instead of properties and property collections)
|
||||||
private DateTime _orderDate;
|
private readonly DateTime _orderDate;
|
||||||
|
|
||||||
// Address is a Value Object pattern example persisted as EF Core 2.0 owned entity
|
// Address is a Value Object pattern example persisted as EF Core 2.0 owned entity
|
||||||
public Address Address { get; private set; }
|
public Address Address { get; private set; }
|
||||||
@ -41,12 +41,15 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
|||||||
|
|
||||||
public static Order NewDraft()
|
public static Order NewDraft()
|
||||||
{
|
{
|
||||||
var order = new Order();
|
var order = new Order
|
||||||
order._isDraft = true;
|
{
|
||||||
|
_isDraft = true
|
||||||
|
};
|
||||||
return order;
|
return order;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Order() {
|
protected Order()
|
||||||
|
{
|
||||||
_orderItems = new List<OrderItem>();
|
_orderItems = new List<OrderItem>();
|
||||||
_isDraft = false;
|
_isDraft = false;
|
||||||
}
|
}
|
||||||
@ -96,14 +99,10 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void SetPaymentId(int id)
|
public void SetPaymentId(int id)
|
||||||
{
|
=> _paymentMethodId = id;
|
||||||
_paymentMethodId = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetBuyerId(int id)
|
public void SetBuyerId(int id)
|
||||||
{
|
=> _buyerId = id;
|
||||||
_buyerId = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetAwaitingValidationStatus()
|
public void SetAwaitingValidationStatus()
|
||||||
{
|
{
|
||||||
@ -183,18 +182,14 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
|||||||
cardNumber, cardSecurityNumber,
|
cardNumber, cardSecurityNumber,
|
||||||
cardHolderName, cardExpiration);
|
cardHolderName, cardExpiration);
|
||||||
|
|
||||||
this.AddDomainEvent(orderStartedDomainEvent);
|
AddDomainEvent(orderStartedDomainEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void StatusChangeException(OrderStatus orderStatusToChange)
|
private void StatusChangeException(OrderStatus orderStatusToChange)
|
||||||
{
|
=> throw new OrderingDomainException($"Is not possible to change the order status from {OrderStatus.Name} to {orderStatusToChange.Name}.");
|
||||||
throw new OrderingDomainException($"Is not possible to change the order status from {OrderStatus.Name} to {orderStatusToChange.Name}.");
|
|
||||||
}
|
|
||||||
|
|
||||||
public decimal GetTotal()
|
public decimal GetTotal()
|
||||||
{
|
=> _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
|
||||||
{
|
{
|
||||||
@ -10,9 +9,9 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
|||||||
// DDD Patterns comment
|
// DDD Patterns comment
|
||||||
// Using private fields, allowed since EF Core 1.1, is a much better encapsulation
|
// Using private fields, allowed since EF Core 1.1, is a much better encapsulation
|
||||||
// aligned with DDD Aggregates and Domain Entities (Instead of properties and property collections)
|
// aligned with DDD Aggregates and Domain Entities (Instead of properties and property collections)
|
||||||
private string _productName;
|
private readonly string _productName;
|
||||||
private string _pictureUrl;
|
private readonly string _pictureUrl;
|
||||||
private decimal _unitPrice;
|
private readonly decimal _unitPrice;
|
||||||
private decimal _discount;
|
private decimal _discount;
|
||||||
private int _units;
|
private int _units;
|
||||||
|
|
||||||
@ -44,19 +43,13 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
|||||||
public string GetPictureUri() => _pictureUrl;
|
public string GetPictureUri() => _pictureUrl;
|
||||||
|
|
||||||
public decimal GetCurrentDiscount()
|
public decimal GetCurrentDiscount()
|
||||||
{
|
=> _discount;
|
||||||
return _discount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int GetUnits()
|
public int GetUnits()
|
||||||
{
|
=> _units;
|
||||||
return _units;
|
|
||||||
}
|
|
||||||
|
|
||||||
public decimal GetUnitPrice()
|
public decimal GetUnitPrice()
|
||||||
{
|
=> _unitPrice;
|
||||||
return _unitPrice;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string GetOrderItemProductName() => _productName;
|
public string GetOrderItemProductName() => _productName;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user