34 lines
1.3 KiB
C#
Raw Normal View History

2025-02-05 22:40:19 +04:00
using AndDietCokeContracts.Enums;
using AndDietCokeContracts.Extensions;
using AndDietCokeContracts.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using AndDietCokeContracts.Exceptions;
namespace AndDietCokeContracts.DataModels;
public class DishDataModel(string id, string dishName, DishType dishType, 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 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 (Price <= 0)
throw new ValidationException("Field Price is less than or equal to 0");
}
}