31 lines
1.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using BitterlyAndExclamationMarkContracts.Enums;
using BitterlyAndExclamationMarkContracts.Extensions;
using BitterlyAndExclamationMarkContracts.Infrastructure;
using System.ComponentModel.DataAnnotations;
public class DishDataModel(string id, string dishName, DishType dishType, string сookId, 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;
public string СookId { get; private set; } = сookId;
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");
if (СookId.IsEmpty())
throw new ValidationException("Field СookId is empty");
if (!СookId.IsGuid())
throw new ValidationException("The value in the field СookId is not a unique identifier");
if (Price <= 0)
throw new ValidationException("Field Price is less than or equal to 0");
}
}