40 lines
1.3 KiB
C#
40 lines
1.3 KiB
C#
|
using SnowMaidenContracts.Enums;
|
|||
|
using SnowMaidenContracts.Exceptions;
|
|||
|
using SnowMaidenContracts.Extensions;
|
|||
|
using SnowMaidenContracts.Infrastructure;
|
|||
|
|
|||
|
namespace SnowMaidenContracts.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");
|
|||
|
}
|
|||
|
}
|