40 lines
1.4 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using IcecreamVan.Enums;
using IcecreamVan.Extensions;
using IcecreamVan.Infrastructure;
using IcecreamVan.Exceptions;
namespace IcecreamVan.DataModels;
// 4. У продукта, в свою очередь, есть производитель (Manufacturer -> Product) и тип (перечисление),
// а также информация об изменениях расценки (Product -> 5. History)
public class ProductDataModel(string id, string productName, ProductType productType, double price, bool isDeleted) : IValidation
{
public string Id { get; private set; } = id;
public string ProductName { get; private set; } = productName;
public ProductType ProductType { get; private set; } = productType;
public double Price { get; private set; } = price;
public bool IsDeleted { get; private set; } = isDeleted;
public void Validate()
{
if (Id.IsEmpty())
throw new ValidationException("Field ID is empty");
if (!Id.IsGuid())
throw new ValidationException("The ID value is NOT a unique identifier");
if (ProductName.IsEmpty())
throw new ValidationException("Name is empty");
if (ProductType == ProductType.None)
throw new ValidationException("Type is empty");
if (Price <= 0)
throw new ValidationException("Field Price is less than or equal to 0");
}
}