35 lines
1.2 KiB
C#
35 lines
1.2 KiB
C#
using CandyHouseContracts.Exceptions;
|
|
using CandyHouseContracts.Extensions;
|
|
using CandyHouseContracts.Infrastructure;
|
|
|
|
namespace CandyHouseContracts.DataModels;
|
|
|
|
public class ClientDiscountDataModel(string clientId, DateTime discountDate, double discountAmount) : IValidation
|
|
{
|
|
private readonly ClientDataModel? _client;
|
|
|
|
public string ClientId { get; private set; } = clientId;
|
|
|
|
public DateTime DiscountDate { get; private set; } = discountDate;
|
|
|
|
public double DiscountAmount { get; private set; } = discountAmount;
|
|
|
|
public string ClientFIO => _client?.FIO ?? string.Empty;
|
|
|
|
public ClientDiscountDataModel(string clientId, DateTime discountDate, double discountAmount, ClientDataModel client) : this(clientId, discountDate, discountAmount)
|
|
{
|
|
_client = client;
|
|
}
|
|
|
|
public void Validate()
|
|
{
|
|
if (ClientId.IsEmpty())
|
|
throw new ValidationException("Field ClientId is empty");
|
|
|
|
if (!ClientId.IsGuid())
|
|
throw new ValidationException("The value in the field ClientId is not a unique identifier");
|
|
|
|
if (DiscountAmount < 0)
|
|
throw new ValidationException("Field DiscountAmount in the field is less than 0");
|
|
}
|
|
} |