37 lines
1.5 KiB
C#
Raw Normal View History

2025-02-10 23:38:41 +04:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using PuferFishContracts.Enums;
using PuferFishContracts.Extensions;
using PuferFishContracts.Exceptions;
using PuferFishContracts.Infrastructure;
namespace PuferFishContracts.DataModels;
2025-03-09 14:28:06 +04:00
public class ProductDataModel(string id, string productName, ProductType productType, double price, List<SupplyProductDataModel> supplies, List<ShopProductDataModel> shop, bool isDeleted) : IValidation
2025-02-10 23:38:41 +04:00
{
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;
2025-03-09 14:28:06 +04:00
public List<SupplyProductDataModel> Supplies { get; private set; } = supplies;
public List<ShopProductDataModel> Shop { get; private set; } = shop;
2025-02-10 23:38:41 +04:00
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 value in the field Id is not a unique identifier");
if (ProductName.IsEmpty())
throw new ValidationException("Field ProductName is empty");
if (ProductType == ProductType.None)
throw new ValidationException("Field ProductType is empty");
if (Price <= 0)
throw new ValidationException("Field Price is less than or equal to 0");
}
}