Files
ChamomileProject/DaisiesContracts/DataModels/ProductDataModel.cs

48 lines
1.6 KiB
C#

using DaisiesContracts.Enum;
using DaisiesContracts.Exceptions;
using DaisiesContracts.Extensions;
using DaisiesContracts.Infrastructure;
namespace DaisiesContracts.DataModels;
public class ProductDataModel : IValidation
{
public string Id { get; private set; }
public string ProductName { get; private set; }
public ProductType ProductType { get; private set; }
public string SupplierId { get; private set; }
public double Price { get; private set; }
public bool IsDeleted { get; private set; }
public ProductDataModel()
{
}
public ProductDataModel(string id, string productName, ProductType productType, string SupplierId, double price, bool isDeleted)
{
Id = id;
ProductName = productName;
ProductType = productType;
this.SupplierId = SupplierId;
Price = price;
IsDeleted = 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 a unique identifier"); }
if (ProductName.IsEmpty()) { throw new ValidationException("Field Id is empty"); }
if (ProductType == ProductType.None) { throw new ValidationException("Field ProductType is empty"); }
if (SupplierId.IsEmpty()) { throw new ValidationException("Field SupplierId is empty"); }
if (!SupplierId.IsGuid()) { throw new ValidationException("The value in the field SupplierId is not a unique identifier"); }
if (Price <= 0) { throw new ValidationException("Field Prise is less than or equal to 0"); }
}
}