31 lines
1.1 KiB
C#
31 lines
1.1 KiB
C#
using CandyHouseBase.Exceptions;
|
|
using CandyHouseBase.Extensions;
|
|
using CandyHouseBase.Infrastructure;
|
|
|
|
namespace CandyHouseBase.DataModels
|
|
{
|
|
public class IngredientDataModel : IValidation
|
|
{
|
|
public string Id { get; private set; }
|
|
public string Name { get; private set; }
|
|
public string Unit { get; private set; }
|
|
public decimal Cost { get; private set; }
|
|
|
|
public IngredientDataModel(string id, string name, string unit, decimal cost)
|
|
{
|
|
Id = id;
|
|
Name = name;
|
|
Unit = unit;
|
|
Cost = cost;
|
|
}
|
|
|
|
public void Validate()
|
|
{
|
|
if (Id.IsEmpty()) throw new ValidationException("Field Id is empty");
|
|
if (!Id.IsGuid()) throw new ValidationException("Id must be a GUID");
|
|
if (Name.IsEmpty()) throw new ValidationException("Field Name is empty");
|
|
if (Unit.IsEmpty()) throw new ValidationException("Field Unit is empty");
|
|
if (Cost < 0) throw new ValidationException("Cost must be non-negative");
|
|
}
|
|
}
|
|
} |