47 lines
1.7 KiB
C#

using PipingHotContrast.Exceptions;
using PipingHotContrast.Extensions;
using PipingHotContrast.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PipingHotContrast.DataModels;
public class SaleDataModel(string id, string workerId, string? restaurantId, double sum, bool isCancel, List<SaleProductDataModel> products) : IValidation
{
public string Id { get; private set; } = id;
public string WorkerId { get; private set; } = workerId;
public string? RestaurantId { get; private set; } = restaurantId;
public DateTime SaleDate { get; private set; }
public double Sum { get; private set; } = sum;
public bool IsCancel { get; private set; } = isCancel;
public List<SaleProductDataModel> 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 (WorkerId.IsEmpty())
throw new ValidationException("Field WorkerId is empty");
if (!WorkerId.IsGuid())
throw new ValidationException("The value in the field WorkerId is not a unique identifier");
if (!RestaurantId?.IsGuid() ?? !RestaurantId?.IsEmpty() ?? false)
throw new ValidationException("The value in the field RestaurantId is not a unique identifier");
if (Sum <= 0)
throw new ValidationException("Field Sum is less than or equal to 0");
if ((Products?.Count ?? 0) == 0)
throw new ValidationException("The sale must include products");
}
}