diff --git a/PipingHotContrast/PipingHotContrast/DataModels/PostDataModel.cs b/PipingHotContrast/PipingHotContrast/DataModels/PostDataModel.cs new file mode 100644 index 0000000..e5453d9 --- /dev/null +++ b/PipingHotContrast/PipingHotContrast/DataModels/PostDataModel.cs @@ -0,0 +1,40 @@ +using PipingHotContrast.Enums; +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 PostDataModel(string id, string postId, string postName, PostType postType, double salary, bool isActual, DateTime changeDate) : IValidation +{ + public string Id { get; private set; } = id; + public string PostId { get; private set; } = postId; + public string PostName { get; private set; } = postName; + public PostType PostType { get; private set; } = postType; + public double Salary { get; private set; } = salary; + public bool IsActual { get; private set; } = isActual; + public DateTime ChangeDate { get; private set; } = changeDate; + + 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 (PostId.IsEmpty()) + throw new ValidationException("Field PostId is empty"); + if (!PostId.IsGuid()) + throw new ValidationException("The value in the field PostId is not a unique identifier"); + if (PostName.IsEmpty()) + throw new ValidationException("Field PostName is empty"); + if (PostType == PostType.None) + throw new ValidationException("Field PostName is empty"); + if (Salary <= 0) + throw new ValidationException("Field Salary is empty"); + } +} diff --git a/PipingHotContrast/PipingHotContrast/DataModels/ProductDataModel.cs b/PipingHotContrast/PipingHotContrast/DataModels/ProductDataModel.cs new file mode 100644 index 0000000..1d5beea --- /dev/null +++ b/PipingHotContrast/PipingHotContrast/DataModels/ProductDataModel.cs @@ -0,0 +1,39 @@ +using PipingHotContrast.Enums; +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 ProductDataModel(string id, string productName, ProductType productType, string restaurantId, 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 string RestaurantId { get; private set; } = restaurantId; + 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 (RestaurantId.IsEmpty()) + throw new ValidationException("Field RestaurantId is empty"); + if (!RestaurantId.IsGuid()) + throw new ValidationException("The value in the field RestaurantId is not a unique identifier"); + if (Price <= 0) + throw new ValidationException("Field Price is empty"); + } +} diff --git a/PipingHotContrast/PipingHotContrast/DataModels/ProductHistoryDataModel.cs b/PipingHotContrast/PipingHotContrast/DataModels/ProductHistoryDataModel.cs new file mode 100644 index 0000000..a00295f --- /dev/null +++ b/PipingHotContrast/PipingHotContrast/DataModels/ProductHistoryDataModel.cs @@ -0,0 +1,28 @@ +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 ProductHistoryDataModel(string productId, double oldPrice) : IValidation +{ + public string ProductId { get; private set; } = productId; + public double OldPrice { get; private set; } = oldPrice; + public DateTime ChangeDate { get; private set; } = DateTime.UtcNow; + + public void Validate() + { + if (ProductId.IsEmpty()) + throw new ValidationException("Field ProductId is empty"); + if (!ProductId.IsGuid()) + throw new ValidationException("The value in the field ProductId is not a unique identifier"); + if (OldPrice <= 0) + throw new ValidationException("Field OldPrice is less than or equal to 0"); + } +} + diff --git a/PipingHotContrast/PipingHotContrast/DataModels/RestaurantDataModel.cs b/PipingHotContrast/PipingHotContrast/DataModels/RestaurantDataModel.cs new file mode 100644 index 0000000..ae1037b --- /dev/null +++ b/PipingHotContrast/PipingHotContrast/DataModels/RestaurantDataModel.cs @@ -0,0 +1,32 @@ +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 RestaurantDataModel(string id, string restaurantName, string? prevRestaurantName, string? prevPrevRestaurantName) : IValidation +{ + public string Id { get; private set; } = id; + public string RestaurantName { get; private set; } = restaurantName; + + public string? PrevRestaurantName { get; private set; } = prevRestaurantName; + + public string? PrevPrevRestaurantName { get; private set; } = prevPrevRestaurantName; + + + 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 (RestaurantName.IsEmpty()) + throw new ValidationException("Field RestaurantName is empty"); + + } +} diff --git a/PipingHotContrast/PipingHotContrast/DataModels/SalaryDataModel.cs b/PipingHotContrast/PipingHotContrast/DataModels/SalaryDataModel.cs new file mode 100644 index 0000000..81f3a33 --- /dev/null +++ b/PipingHotContrast/PipingHotContrast/DataModels/SalaryDataModel.cs @@ -0,0 +1,27 @@ +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 SalaryDataModel(string workerId, DateTime salaryDate, double salary) : IValidation +{ + public string WorkerId { get; private set; } = workerId; + public DateTime SalaryDate { get; private set; } = salaryDate; + public double Salary { get; private set; } = salary; + + public void Validate() + { + 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 (Salary <= 0) + throw new ValidationException("Field Salary is less than or equal to 0"); + } +} diff --git a/PipingHotContrast/PipingHotContrast/DataModels/SaleDataModel.cs b/PipingHotContrast/PipingHotContrast/DataModels/SaleDataModel.cs new file mode 100644 index 0000000..71831f8 --- /dev/null +++ b/PipingHotContrast/PipingHotContrast/DataModels/SaleDataModel.cs @@ -0,0 +1,46 @@ +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 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 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"); + } +} + diff --git a/PipingHotContrast/PipingHotContrast/DataModels/SaleProductDataModel.cs b/PipingHotContrast/PipingHotContrast/DataModels/SaleProductDataModel.cs new file mode 100644 index 0000000..3e640e2 --- /dev/null +++ b/PipingHotContrast/PipingHotContrast/DataModels/SaleProductDataModel.cs @@ -0,0 +1,32 @@ +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 SaleProductDataModel(string saleId, string productId, int count) : IValidation +{ + public string SaleId { get; private set; } = saleId; + public string ProductId { get; private set; } = productId; + public int Count { get; private set; } = count; + + public void Validate() + { + if (SaleId.IsEmpty()) + throw new ValidationException("Field SaleId is empty"); + if (!SaleId.IsGuid()) + throw new ValidationException("The value in the field SaleId is not a unique identifier"); + if (ProductId.IsEmpty()) + throw new ValidationException("Field ProductId is empty"); + if (!ProductId.IsGuid()) + throw new ValidationException("The value in the field ProductId is not a unique identifier"); + if (Count <= 0) + throw new ValidationException("Field Count is less than or equal to 0"); + } +} + diff --git a/PipingHotContrast/PipingHotContrast/DataModels/WorkerDataModel.cs b/PipingHotContrast/PipingHotContrast/DataModels/WorkerDataModel.cs new file mode 100644 index 0000000..12dde0c --- /dev/null +++ b/PipingHotContrast/PipingHotContrast/DataModels/WorkerDataModel.cs @@ -0,0 +1,42 @@ +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 WorkerDataModel(string id, string fio, string postId, DateTime birthDate, DateTime employmentDate, bool isDeleted) : IValidation +{ + public string Id { get; private set; } = id; + public string FIO { get; private set; } = fio; + public string PostId { get; private set; } = postId; + public DateTime BirthDate { get; private set; } = birthDate; + public DateTime EmploymentDate { get; private set; } = employmentDate; + 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 (FIO.IsEmpty()) + throw new ValidationException("Field FIO is empty"); + if (PostId.IsEmpty()) + throw new ValidationException("Field PostId is empty"); + if (!PostId.IsGuid()) + throw new ValidationException("The value in the field PostId is not a unique identifier"); + if (BirthDate.Date > DateTime.Now.AddYears(-16).Date) + throw new ValidationException($"Minors cannot be hired (BirthDate = {BirthDate.ToShortDateString()})"); + + if (EmploymentDate.Date < BirthDate.Date) + throw new ValidationException("The date of employment cannot be less than the date of birth"); + + if ((EmploymentDate - BirthDate).TotalDays / 365 < 16) // EmploymentDate.Year - BirthDate.Year + throw new ValidationException($"Minors cannot be hired (EmploymentDate - {EmploymentDate.ToShortDateString()}, BirthDate - {BirthDate.ToShortDateString()})"); + } +} diff --git a/PipingHotContrast/PipingHotContrast/Enums/PostType.cs b/PipingHotContrast/PipingHotContrast/Enums/PostType.cs new file mode 100644 index 0000000..24b82e4 --- /dev/null +++ b/PipingHotContrast/PipingHotContrast/Enums/PostType.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PipingHotContrast.Enums; + +public enum PostType +{ + None = 0, + Operator = 1, + Aggregator = 2, + Deliveryman = 3 + +} diff --git a/PipingHotContrast/PipingHotContrast/Enums/ProductType.cs b/PipingHotContrast/PipingHotContrast/Enums/ProductType.cs new file mode 100644 index 0000000..cf758e8 --- /dev/null +++ b/PipingHotContrast/PipingHotContrast/Enums/ProductType.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PipingHotContrast.Enums; + +public enum ProductType +{ + None = 0, + Pizza = 1, + Sushi = 2, + Сocktail = 3 +} diff --git a/PipingHotContrast/PipingHotContrast/Exceptions/ValidationException.cs b/PipingHotContrast/PipingHotContrast/Exceptions/ValidationException.cs new file mode 100644 index 0000000..884ec40 --- /dev/null +++ b/PipingHotContrast/PipingHotContrast/Exceptions/ValidationException.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PipingHotContrast.Exceptions; + +public class ValidationException(string message) : Exception(message) +{ +} diff --git a/PipingHotContrast/PipingHotContrast/Extensions/StringExtensions.cs b/PipingHotContrast/PipingHotContrast/Extensions/StringExtensions.cs new file mode 100644 index 0000000..f0a6f15 --- /dev/null +++ b/PipingHotContrast/PipingHotContrast/Extensions/StringExtensions.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PipingHotContrast.Extensions; + +public static class StringExtensions +{ + public static bool IsEmpty(this string str) + { + return string.IsNullOrEmpty(str); + } + public static bool IsGuid(this string str) + { + return Guid.TryParse(str, out _); + } +} + diff --git a/PipingHotContrast/PipingHotContrast/Infrastructure/IValidation.cs b/PipingHotContrast/PipingHotContrast/Infrastructure/IValidation.cs new file mode 100644 index 0000000..2d157de --- /dev/null +++ b/PipingHotContrast/PipingHotContrast/Infrastructure/IValidation.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PipingHotContrast.Infrastructure; + +public interface IValidation +{ + void Validate(); +}