diff --git a/PuferFishContracts/PuferFishContracts/DataModels/PointsDataModel.cs b/PuferFishContracts/PuferFishContracts/DataModels/PointsDataModel.cs new file mode 100644 index 0000000..bf3b0e8 --- /dev/null +++ b/PuferFishContracts/PuferFishContracts/DataModels/PointsDataModel.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PuferFishContracts.Infrastructure; +using PuferFishContracts.Extensions; +using PuferFishContracts.Exceptions; + +namespace PuferFishContracts.DataModels; + +public class PointsDataModel(string buyerId, DateTime pointsDate, double buyerPoints) : IValidation +{ + public string BuyerId { get; private set; } = buyerId; + public DateTime PointsDate { get; private set; } = pointsDate; + public double Points { get; private set; } = buyerPoints; + public void Validate() + { + if (BuyerId.IsEmpty()) + throw new ValidationException("Field BuyerId is empty"); + if (!BuyerId.IsGuid()) + throw new ValidationException("The value in the field BuyerId is not a unique identifier"); + if (Points <= 0) + throw new ValidationException("Field Points is less than or equal to 0"); + } +} diff --git a/PuferFishContracts/PuferFishContracts/DataModels/SaleDataModel.cs b/PuferFishContracts/PuferFishContracts/DataModels/SaleDataModel.cs new file mode 100644 index 0000000..3ff5b0a --- /dev/null +++ b/PuferFishContracts/PuferFishContracts/DataModels/SaleDataModel.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PuferFishContracts.Infrastructure; +using PuferFishContracts.Extensions; +using PuferFishContracts.Exceptions; +using System.Xml; + +namespace PuferFishContracts.DataModels; + +public class SaleDataModel(string id, string workerId, string? buyerId, double sum, double points, bool isCancel, List products) : IValidation +{ + public string Id { get; private set; } = id; + public string WorkerId { get; private set; } = workerId; + public string? BuyerId { get; private set; } = buyerId; + public DateTime SaleDate { get; private set; } = DateTime.UtcNow; + public double Sum { get; private set; } = sum; + public double Points { get; private set; } = points; + public bool IsCancel { get; private set; } = isCancel; + public List 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 (!BuyerId?.IsGuid() ?? !BuyerId?.IsEmpty() ?? false) + throw new ValidationException("The value in the field BuyerId 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"); + } +}