Files
AndDietCoke/AndDietCokeProject/AndDietCokeProject/DataModels/DishDataModel.cs

44 lines
1.9 KiB
C#

using AndDietCokeContracts.Extensions;
using AndDietCokeContracts.Infrastrusture;
using AndDietCokeContracts.Exceptions;
using AndDietCokeContracts.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using AndDietCokeContracts.Resources;
using Microsoft.Extensions.Localization;
using AndDietCokeContracts.Mapper;
namespace AndDietCokeContracts.DataModels;
internal 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 DishDataModel(string id, string dishName, int dishType, double price) : this(id, dishName, (DishType)dishType, price, false) { }
public DishDataModel() : this("", "", DishType.None, 0, false)
{
}
public void Validate(IStringLocalizer<Messages> localizer)
{
if (Id.IsEmpty())
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "Id"));
if (!Id.IsGuid())
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "Id"));
if (DishName.IsEmpty())
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "DishName"));
if (DishType == DishType.None)
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "DishType"));
if (Price <= 0)
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageLessOrEqualZero"], "Price"));
}
}