2025-02-17 16:55:47 +04:00

30 lines
1.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RomashkiContracts.Exceptions;
using RomashkiContracts.Extensions;
using RomashkiContracts.Infrastructure;
namespace RomashkiContract.DataModels;
public class DiscountDataModel(string buyerId, DateTime discountDate, double discountSize) : IValidation
{
public string BuyerId{ get; private set; } = buyerId;
public DateTime DiscountDate { get; private set; } = discountDate;
public double DiscountSize { get; private set; } = discountSize;
public void Validate()
{
if (BuyerId.IsEmpty())
throw new ValidationException("Field BuyerId is empty");
if (!BuyerId.IsGuid())
throw new ValidationException("The value in the field BuyerId is not a unique identifier");
if (discountSize < 0)
throw new ValidationException("Field DiscountSize is less than or equal to 0");
if (discountSize > 100)
throw new ValidationException("Field DiscountSize is more than 100");
}
}