36 lines
1.4 KiB
C#
36 lines
1.4 KiB
C#
using CandyHouseContracts.Enums;
|
|
using CandyHouseContracts.Exceptions;
|
|
using CandyHouseContracts.Extensions;
|
|
using CandyHouseContracts.Infrastructure;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using static System.Runtime.InteropServices.JavaScript.JSType;
|
|
|
|
namespace CandyHouseContracts.DataModels;
|
|
|
|
public class SuppliesDataModel(string id, ProductType productType, DateTime productuionDate, int count, List<ProductSuppliesDataModel> products) : IValidation
|
|
{
|
|
public string Id { get; private set; } = id;
|
|
public ProductType ProductType { get; private set; } = productType;
|
|
public DateTime ProductuionDate { get; private set; } = productuionDate;
|
|
public int Count { get; private set; } = count;
|
|
public List<ProductSuppliesDataModel> Products { get; private set; } = products;
|
|
|
|
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 (ProductType == ProductType.None)
|
|
throw new ValidationException("Field Type is empty");
|
|
if (Count <= 0)
|
|
throw new ValidationException("Field Count is less than or equal to 0");
|
|
if ((Products?.Count ?? 0) == 0)
|
|
throw new ValidationException("The sale must include products");
|
|
}
|
|
}
|