37 lines
1.3 KiB
C#
37 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using RomashkiContracts.Enums;
|
|
using RomashkiContracts.Extensions;
|
|
using RomashkiContracts.Infrastructure;
|
|
using System.Xml;
|
|
using RomashkiContracts.Exceptions;
|
|
|
|
namespace RomashkiContracts.DataModels;
|
|
|
|
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 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");
|
|
}
|
|
}
|
|
|