using System.Collections.Generic; using CandyHouseBase.Exceptions; using CandyHouseBase.Extensions; using CandyHouseBase.Infrastructure; namespace CandyHouseBase.DataModels { public class ProductDataModel : IValidation { public string Id { get; private set; } public string Name { get => name; private set { if (!name.IsEmpty()) OldName = name; name = value.Trim(); } } public string Description { get => description; private set { if (!description.IsEmpty()) OldDescription = description; description = value.Trim(); } } public string OldName { get; private set; } public string OldDescription { get; private set; } private string name; private string description; public List IngredientsItems { get; private set; } public ProductDataModel(string id, string name, string description, List ingredients) { Id = id; Name = name; Description = description; IngredientsItems = ingredients; } 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 (Description.IsEmpty()) throw new ValidationException("Field Description is empty"); if (IngredientsItems.Count == 0) throw new ValidationException("Field IngredientsItems is empty"); } } }