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 ProductDataModel(string id, string name, string description) { Id = id; Name = name; Description = description; } 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"); } } }