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
|
||||
: Entity
|
||||
{
|
||||
private string _alias;
|
||||
private string _cardNumber;
|
||||
private string _securityNumber;
|
||||
private string _cardHolderName;
|
||||
private DateTime _expiration;
|
||||
private readonly string _alias;
|
||||
private readonly string _cardNumber;
|
||||
private readonly string _securityNumber;
|
||||
private readonly string _cardHolderName;
|
||||
private readonly DateTime _expiration;
|
||||
|
||||
private int _cardTypeId;
|
||||
private readonly int _cardTypeId;
|
||||
public CardType CardType { get; private set; }
|
||||
|
||||
|
||||
@ -36,11 +36,9 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.B
|
||||
_cardTypeId = cardTypeId;
|
||||
}
|
||||
|
||||
public bool IsEqualTo(int cardTypeId, string cardNumber,DateTime expiration)
|
||||
{
|
||||
return _cardTypeId == cardTypeId
|
||||
public bool IsEqualTo(int cardTypeId, string cardNumber, DateTime expiration)
|
||||
=> _cardTypeId == cardTypeId
|
||||
&& _cardNumber == cardNumber
|
||||
&& _expiration == expiration;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
||||
// DDD Patterns comment
|
||||
// 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)
|
||||
private DateTime _orderDate;
|
||||
private readonly DateTime _orderDate;
|
||||
|
||||
// Address is a Value Object pattern example persisted as EF Core 2.0 owned entity
|
||||
public Address Address { get; private set; }
|
||||
@ -41,12 +41,15 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
||||
|
||||
public static Order NewDraft()
|
||||
{
|
||||
var order = new Order();
|
||||
order._isDraft = true;
|
||||
var order = new Order
|
||||
{
|
||||
_isDraft = true
|
||||
};
|
||||
return order;
|
||||
}
|
||||
|
||||
protected Order() {
|
||||
protected Order()
|
||||
{
|
||||
_orderItems = new List<OrderItem>();
|
||||
_isDraft = false;
|
||||
}
|
||||
@ -96,14 +99,10 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
||||
}
|
||||
|
||||
public void SetPaymentId(int id)
|
||||
{
|
||||
_paymentMethodId = id;
|
||||
}
|
||||
=> _paymentMethodId = id;
|
||||
|
||||
public void SetBuyerId(int id)
|
||||
{
|
||||
_buyerId = id;
|
||||
}
|
||||
=> _buyerId = id;
|
||||
|
||||
public void SetAwaitingValidationStatus()
|
||||
{
|
||||
@ -183,18 +182,14 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
||||
cardNumber, cardSecurityNumber,
|
||||
cardHolderName, cardExpiration);
|
||||
|
||||
this.AddDomainEvent(orderStartedDomainEvent);
|
||||
AddDomainEvent(orderStartedDomainEvent);
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
return _orderItems.Sum(o => o.GetUnits() * o.GetUnitPrice());
|
||||
}
|
||||
=> _orderItems.Sum(o => o.GetUnits() * o.GetUnitPrice());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
using Microsoft.eShopOnContainers.Services.Ordering.Domain.Seedwork;
|
||||
using Ordering.Domain.Exceptions;
|
||||
using System;
|
||||
|
||||
namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.OrderAggregate
|
||||
{
|
||||
@ -10,9 +9,9 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
||||
// DDD Patterns comment
|
||||
// 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)
|
||||
private string _productName;
|
||||
private string _pictureUrl;
|
||||
private decimal _unitPrice;
|
||||
private readonly string _productName;
|
||||
private readonly string _pictureUrl;
|
||||
private readonly decimal _unitPrice;
|
||||
private decimal _discount;
|
||||
private int _units;
|
||||
|
||||
@ -44,19 +43,13 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
|
||||
public string GetPictureUri() => _pictureUrl;
|
||||
|
||||
public decimal GetCurrentDiscount()
|
||||
{
|
||||
return _discount;
|
||||
}
|
||||
=> _discount;
|
||||
|
||||
public int GetUnits()
|
||||
{
|
||||
return _units;
|
||||
}
|
||||
=> _units;
|
||||
|
||||
public decimal GetUnitPrice()
|
||||
{
|
||||
return _unitPrice;
|
||||
}
|
||||
=> _unitPrice;
|
||||
|
||||
public string GetOrderItemProductName() => _productName;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user