From 0e159d5d0e88c15a9b6a9f4c27641557c2830ce8 Mon Sep 17 00:00:00 2001 From: Baryshev Dmitry Date: Mon, 10 Feb 2025 22:47:57 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B2=D1=81=D0=B5=20=D0=BC=D0=BE=D0=B4=D0=B5?= =?UTF-8?q?=D0=BB=D0=B8=20=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BD=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DataModels/CropDataModel.cs | 12 ++--- .../DataModels/CropHistoryDataModel.cs | 31 ------------ .../DataModels/HarvestDataModel.cs | 5 +- .../DataModels/SupplyCropDataModel.cs | 37 ++++++++++++++ .../DataModels/SupplyDataModel.cs | 49 +++++++++++++++++++ .../DataModels/SupplyHistoryDataModel.cs | 28 +++++++++++ SeniorPomidorContracts/Enums/DiscountType.cs | 15 ++++++ 7 files changed, 139 insertions(+), 38 deletions(-) delete mode 100644 SeniorPomidorContracts/DataModels/CropHistoryDataModel.cs create mode 100644 SeniorPomidorContracts/DataModels/SupplyCropDataModel.cs create mode 100644 SeniorPomidorContracts/DataModels/SupplyDataModel.cs create mode 100644 SeniorPomidorContracts/DataModels/SupplyHistoryDataModel.cs create mode 100644 SeniorPomidorContracts/Enums/DiscountType.cs diff --git a/SeniorPomidorContracts/DataModels/CropDataModel.cs b/SeniorPomidorContracts/DataModels/CropDataModel.cs index b9a083b..32845f5 100644 --- a/SeniorPomidorContracts/DataModels/CropDataModel.cs +++ b/SeniorPomidorContracts/DataModels/CropDataModel.cs @@ -35,14 +35,14 @@ public class CropDataModell(string id, string harvestId, string cropName, double throw new ValidationException("Field Id is empty"); if (!Id.IsGuid()) - throw new ValidationException("The value in the field Id is not a unique identifier"); - + throw new ValidationException("The value in the field Id is not a unique identifier"); + if (HarvestId.IsEmpty()) throw new ValidationException("Field HarvestId is empty"); if (!HarvestId.IsGuid()) - throw new ValidationException("The value in the field HarvestId is not a unique identifier"); - + throw new ValidationException("The value in the field HarvestId is not a unique identifier"); + if (CropName.IsEmpty()) throw new ValidationException("Field CropName is empty"); @@ -50,6 +50,6 @@ public class CropDataModell(string id, string harvestId, string cropName, double throw new ValidationException("Field CropType is empty"); if (Price <= 0) - throw new ValidationException("Field Price is less than or equal to 0"); + throw new ValidationException("Field Price is less than or equal to 0"); } -} +} \ No newline at end of file diff --git a/SeniorPomidorContracts/DataModels/CropHistoryDataModel.cs b/SeniorPomidorContracts/DataModels/CropHistoryDataModel.cs deleted file mode 100644 index 918d0af..0000000 --- a/SeniorPomidorContracts/DataModels/CropHistoryDataModel.cs +++ /dev/null @@ -1,31 +0,0 @@ -using SeniorPomidorContracts.Extensions; -using SeniorPomidorContracts.Infrastructure; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SeniorPomidorContracts.DataModels; - -public class CropHistoryDataModell(string cropId, double oldPrice) : IValidation -{ - public string CropId { get; private set; } = cropId; - - public double OldPrice { get; private set; } = oldPrice; - - public DateTime ChangeDate { get; private set; } = DateTime.UtcNow; - - public void Validate() - { - if (CropId.IsEmpty()) - throw new ValidationException("Field CropId is empty"); - - if (!CropId.IsGuid()) - throw new ValidationException("The value in the field CropId is not a unique identifier"); - - if (OldPrice <= 0) - throw new ValidationException("Field OldPrice is less than or equal to 0"); - } -} diff --git a/SeniorPomidorContracts/DataModels/HarvestDataModel.cs b/SeniorPomidorContracts/DataModels/HarvestDataModel.cs index b84a81b..1a362b9 100644 --- a/SeniorPomidorContracts/DataModels/HarvestDataModel.cs +++ b/SeniorPomidorContracts/DataModels/HarvestDataModel.cs @@ -28,9 +28,12 @@ public class HarvestDataModel(string id, string harvestName throw new ValidationException("Field Id is empty"); if (Id.IsGuid()) - throw new ValidationException("\"The value in the field Id is not a unique identifier"); + throw new ValidationException("The value in the field Id is not a unique identifier"); if (HarvestName.IsEmpty()) throw new ValidationException("Field HarvestName is empty"); + + if (HarvestAmount < 0) + throw new ValidationException("Field HarvestAmount is less than 0"); } } diff --git a/SeniorPomidorContracts/DataModels/SupplyCropDataModel.cs b/SeniorPomidorContracts/DataModels/SupplyCropDataModel.cs new file mode 100644 index 0000000..1191507 --- /dev/null +++ b/SeniorPomidorContracts/DataModels/SupplyCropDataModel.cs @@ -0,0 +1,37 @@ +using SeniorPomidorContracts.Extensions; +using SeniorPomidorContracts.Infrastructure; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SeniorPomidorContracts.DataModels; + +public class SupplyCropDataModel(string supplyId, string cropId, int amount) : IValidation +{ + public string SupplyId { get; private set; } = supplyId; + + public string CropId { get; private set; } = cropId; + + public int Amount { get; private set; } = amount; + + public void Validate() + { + if (SupplyId.IsEmpty()) + throw new ValidationException("Field SupplyId is empty"); + + if (!SupplyId.IsGuid()) + throw new ValidationException("The value in the field SupplyId is not a unique identifier"); + + if (CropId.IsEmpty()) + throw new ValidationException("Field CropId is empty"); + + if (!CropId.IsGuid()) + throw new ValidationException("The value in the field CropId is not a unique identifier"); + + if (Amount <= 0) + throw new ValidationException("Field Amount is less than or equal to 0"); + } +} diff --git a/SeniorPomidorContracts/DataModels/SupplyDataModel.cs b/SeniorPomidorContracts/DataModels/SupplyDataModel.cs new file mode 100644 index 0000000..c562070 --- /dev/null +++ b/SeniorPomidorContracts/DataModels/SupplyDataModel.cs @@ -0,0 +1,49 @@ +using SeniorPomidorContracts.Enums; +using SeniorPomidorContracts.Extensions; +using SeniorPomidorContracts.Infrastructure; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SeniorPomidorContracts.DataModels; + +public class SupplyDataModel(string id, string supplierId, int sum, DateTime supplyDate, + bool isCancel, List crops, DiscountType discountType, double discount) : IValidation +{ + public string Id { get; private set; } = id; + + public string? SupplierId { get; private set; } = supplierId; + + public int Sum { get; private set; } = sum; + + public DateTime SupplyDate { get; private set; } = supplyDate; + + public List Crops { get; private set; } = crops; + + public DiscountType DiscountType { get; private set; } = discountType; + + public double Discount { get; private set; } = discount; + + public bool IsCancel { get; private set; } = isCancel; + + 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 (!SupplierId?.IsGuid() ?? !SupplierId?.IsEmpty() ?? false) + throw new ValidationException("The value in the field SupplierId is not a unique identifier"); + + if (Sum <= 0) + throw new ValidationException("Field Sum is less than or equal to 0"); + + if ((Crops?.Count ?? 0) == 0) + throw new ValidationException("The sale must include products"); + } +} diff --git a/SeniorPomidorContracts/DataModels/SupplyHistoryDataModel.cs b/SeniorPomidorContracts/DataModels/SupplyHistoryDataModel.cs new file mode 100644 index 0000000..7e165e8 --- /dev/null +++ b/SeniorPomidorContracts/DataModels/SupplyHistoryDataModel.cs @@ -0,0 +1,28 @@ +using SeniorPomidorContracts.Extensions; +using SeniorPomidorContracts.Infrastructure; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SeniorPomidorContracts.DataModels; + +public class SupplyHistoryDataModell(string id, string SupplyId) : IValidation +{ + public string Id { get; set; } = id; + + public string SupplyId { get; private set; } = SupplyId; + + public DateTime SupplyDate { get; private set; } = DateTime.UtcNow; + + public void Validate() + { + if (SupplyId.IsEmpty()) + throw new ValidationException("Field SupplyId is empty"); + + if (!SupplyId.IsGuid()) + throw new ValidationException("The value in the field SupplyId is not a unique identifier"); + } +} diff --git a/SeniorPomidorContracts/Enums/DiscountType.cs b/SeniorPomidorContracts/Enums/DiscountType.cs new file mode 100644 index 0000000..29c3c82 --- /dev/null +++ b/SeniorPomidorContracts/Enums/DiscountType.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SeniorPomidorContracts.Enums; +[Flags] +public enum DiscountType +{ + None = 0, + OnSale = 1, + RegularSupplier = 2, + Certificate = 4 +}