20 lines
886 B
C#
20 lines
886 B
C#
using BitterlyAndExclamationMarkContracts.Exceptions;
|
|
using BitterlyAndExclamationMarkContracts.Extensions;
|
|
using BitterlyAndExclamationMarkContracts.Infrastructure;
|
|
namespace BitterlyAndExclamationMarkContracts.DataModels;
|
|
|
|
public class DishHistoryDataModel(string dishId, double oldPrice) : IValidation
|
|
{
|
|
public string DishId { get; private set; } = dishId;
|
|
public double OldPrice { get; private set; } = oldPrice;
|
|
public DateTime ChangeDate { get; private set; } = DateTime.UtcNow;
|
|
public void Validate()
|
|
{
|
|
if (DishId.IsEmpty())
|
|
throw new ValidationException("Field DishId is empty");
|
|
if (!DishId.IsGuid())
|
|
throw new ValidationException("The value in the field DishId is not a unique identifier");
|
|
if (OldPrice <= 0)
|
|
throw new ValidationException("Field OldPrice is less than or equal to 0");
|
|
}
|
|
} |