Files
ChamomileProject/DaisiesContracts/DataModels/ClientDiscountDataModel.cs

54 lines
1.7 KiB
C#

using DaisiesContracts.Exceptions;
using DaisiesContracts.Extensions;
using DaisiesContracts.Infrastructure;
namespace DaisiesContracts.DataModels;
public class ClientDiscountDataModel(string buyerId, double totalSum, double personalDiscount, DateTime? discountDate = null) : IValidation
{
private readonly BuyerDataModel? _buyer;
public string BuyerId { get; private set; } = buyerId;
public double TotalSum { get; private set; } = totalSum;
public double PersonalDiscount { get; private set; } = personalDiscount;
public DateTime DiscountDate { get; private set; } = discountDate ?? DateTime.UtcNow;
public string BuyerFIO => _buyer?.FIO ?? string.Empty;
public ClientDiscountDataModel(string? buyerId, double totalSum, double personalDiscount, BuyerDataModel buyer) : this(buyerId, totalSum, personalDiscount)
{
_buyer = buyer;
}
public ClientDiscountDataModel(string? buyerId, double totalSum, double personalDiscount, BuyerDataModel buyer, DateTime discountDate) : this(buyerId, totalSum, personalDiscount, discountDate)
{
_buyer = buyer;
}
public void Validate()
{
if (BuyerId.IsEmpty())
{
throw new ValidationException("Field Id is empty");
}
if (!BuyerId.IsGuid())
{
throw new ValidationException("The value in the field Id is not a unique identifier");
}
if (TotalSum < 0)
{
throw new ValidationException("TotalSum cannot be less than zero");
}
if (PersonalDiscount < 0)
{
throw new ValidationException("PersonalDiscount cannot be less than zero");
}
}
}