28 lines
1.4 KiB
C#
Raw Normal View History

using BitterlyAndExclamationMarkContracts.Enums;
2025-02-11 17:33:57 +04:00
using BitterlyAndExclamationMarkContracts.Exceptions;
using BitterlyAndExclamationMarkContracts.Extensions;
using BitterlyAndExclamationMarkContracts.Infrastructure;
2025-02-11 17:33:57 +04:00
public class DishDataModel(string id, string dishName, DishType dishType, Ingredients ingredients, double price, bool isDeleted) : IValidation
{
public string Id { get; private set; } = id;
public string DishName { get; private set; } = dishName;
public DishType DishType { get; private set; } = dishType;
2025-02-11 17:33:57 +04:00
public Ingredients Ingredients { get; private set; } = ingredients;
public double Price { get; private set; } = price;
public bool IsDeleted { get; private set; } = isDeleted;
public void Validate()
{
if (Id.IsEmpty())
throw new ValidationException("Field Id is empty");
if (!Id.IsGuid())
throw new ValidationException("The value in the field Id is not a unique identifier");
if (DishName.IsEmpty())
throw new ValidationException("Field DishName is empty");
if (DishType == DishType.None)
throw new ValidationException("Field DishType is empty");
2025-02-11 17:33:57 +04:00
if (Ingredients == Ingredients.None)
throw new ValidationException("Field Ingredients is empty");
if (Price <= 0)
throw new ValidationException("Field Price is less than or equal to 0");
}
}