57 lines
1.7 KiB
C#
Raw Normal View History

2025-02-13 16:25:09 +04:00
using System.Collections.Generic;
2025-02-12 22:16:56 +04:00
using CandyHouseBase.Exceptions;
using CandyHouseBase.Extensions;
using CandyHouseBase.Infrastructure;
namespace CandyHouseBase.DataModels
{
public class ProductDataModel : IValidation
{
public string Id { get; private set; }
2025-02-13 16:13:21 +04:00
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;
2025-02-13 16:25:09 +04:00
public List<IngredientDataModel> IngredientsItems { get; private set; }
2025-02-12 22:16:56 +04:00
2025-02-13 16:25:09 +04:00
public ProductDataModel(string id, string name, string description, List<IngredientDataModel> ingredients)
2025-02-12 22:16:56 +04:00
{
Id = id;
Name = name;
Description = description;
2025-02-13 16:25:09 +04:00
IngredientsItems = ingredients;
2025-02-12 22:16:56 +04:00
}
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");
2025-02-13 16:13:21 +04:00
if (Description.IsEmpty()) throw new ValidationException("Field Description is empty");
2025-02-12 22:16:56 +04:00
}
}
}