diff --git a/North_Bridge/North_Bridge_Contract/DataModels/PostDataModel.cs b/North_Bridge/North_Bridge_Contract/DataModels/PostDataModel.cs new file mode 100644 index 0000000..73e5d11 --- /dev/null +++ b/North_Bridge/North_Bridge_Contract/DataModels/PostDataModel.cs @@ -0,0 +1,58 @@ +using North_Bridge_Contract.Infrastructure; +using North_Bridge_Contract.Enums; +using North_Bridge_Contract.Extentions; +using North_Bridge_Contract.Exceptions; + +namespace North_Bridge_Contract.DataModels; + +public class PostDataModel : IValidation +{ + public string Id { get; private set; } + + public string PostId { get; private set; } + + public string PostName { get; private set; } + + public PostType PostType { get; private set; } + + public double Salary { get; private set; } + + public bool IsActual { get; private set; } + + public DateTime ChangeDate { get; private set; } + + public PostDataModel(string id, string postId, string postName, PostType postType, double salary, bool isActual, DateTime changeDate) + { + Id = id; + PostId = postId; + PostName = postName; + PostType = postType; + Salary = salary; + IsActual = isActual; + ChangeDate = 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 PostType is empty"); + + if (Salary <= 0) + throw new ValidationException("Field Salary is empty"); + } +} \ No newline at end of file diff --git a/North_Bridge/North_Bridge_Contract/DataModels/ProductDataModel.cs b/North_Bridge/North_Bridge_Contract/DataModels/ProductDataModel.cs new file mode 100644 index 0000000..1aacca8 --- /dev/null +++ b/North_Bridge/North_Bridge_Contract/DataModels/ProductDataModel.cs @@ -0,0 +1,46 @@ +using North_Bridge_Contract.Enums; +using North_Bridge_Contract.Exceptions; +using North_Bridge_Contract.Extentions; +using North_Bridge_Contract.Infrastructure; + +namespace North_Bridge_Contract.DataModels; + +public class ProductDataModel : IValidation +{ + public string Id { get; private set; } + + public string ProductName { get; private set; } + + public ProductType ProductType { get; private set; } + + public double Price { get; private set; } + + public bool IsDeleted { get; private set; } + + public ProductDataModel(string id, string productName, ProductType productType, double price, bool isDeleted) + { + Id = id; + ProductName = productName; + ProductType = productType; + Price = price; + IsDeleted = 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 (Price <= 0) + throw new ValidationException("Field Price is less than or equal to 0"); + } +} \ No newline at end of file diff --git a/North_Bridge/North_Bridge_Contract/DataModels/ProductForSaleDataModel.cs b/North_Bridge/North_Bridge_Contract/DataModels/ProductForSaleDataModel.cs new file mode 100644 index 0000000..e272b3f --- /dev/null +++ b/North_Bridge/North_Bridge_Contract/DataModels/ProductForSaleDataModel.cs @@ -0,0 +1,39 @@ +using North_Bridge_Contract.Exceptions; +using North_Bridge_Contract.Extentions; +using North_Bridge_Contract.Infrastructure; + +namespace North_Bridge_Contract.DataModels; + +public class ProductForSaleDataModel : IValidation +{ + public string SaleId { get; private set; } + + public string ProductId { get; private set; } + + public int Count { get; private set; } + + public ProductForSaleDataModel(string saleId, string productId, int count) + { + SaleId = saleId; + ProductId = productId; + Count = 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"); + } +} \ No newline at end of file diff --git a/North_Bridge/North_Bridge_Contract/DataModels/ProductHistoryDataModel.cs b/North_Bridge/North_Bridge_Contract/DataModels/ProductHistoryDataModel.cs new file mode 100644 index 0000000..0ef0774 --- /dev/null +++ b/North_Bridge/North_Bridge_Contract/DataModels/ProductHistoryDataModel.cs @@ -0,0 +1,33 @@ +using North_Bridge_Contract.Exceptions; +using North_Bridge_Contract.Extentions; +using North_Bridge_Contract.Infrastructure; + +namespace North_Bridge_Contract.DataModels; + +public class ProductHistoryDataModel : IValidation +{ + public string ProductId { get; private set; } + + public double OldPrice { get; private set; } + + public DateTime ChangeDate { get; private set; } + + public ProductHistoryDataModel(string productId, double oldPrice) + { + ProductId = productId; + OldPrice = oldPrice; + ChangeDate = 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"); + } +} \ No newline at end of file diff --git a/North_Bridge/North_Bridge_Contract/DataModels/SalaryDataModel.cs b/North_Bridge/North_Bridge_Contract/DataModels/SalaryDataModel.cs new file mode 100644 index 0000000..b5267ac --- /dev/null +++ b/North_Bridge/North_Bridge_Contract/DataModels/SalaryDataModel.cs @@ -0,0 +1,33 @@ +using North_Bridge_Contract.Exceptions; +using North_Bridge_Contract.Extentions; +using North_Bridge_Contract.Infrastructure; + +namespace North_Bridge_Contract.DataModels; + +public class SalaryDataModel : IValidation +{ + public string WorkerId { get; private set; } + + public DateTime SalaryDate { get; private set; } + + public double Salary { get; private set; } + + public SalaryDataModel(string workerId, DateTime salaryDate, double salary) + { + WorkerId = workerId; + SalaryDate = salaryDate; + Salary = 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"); + } +} \ No newline at end of file diff --git a/North_Bridge/North_Bridge_Contract/DataModels/SaleDataModel.cs b/North_Bridge/North_Bridge_Contract/DataModels/SaleDataModel.cs new file mode 100644 index 0000000..c15d1d1 --- /dev/null +++ b/North_Bridge/North_Bridge_Contract/DataModels/SaleDataModel.cs @@ -0,0 +1,51 @@ +using North_Bridge_Contract.Exceptions; +using North_Bridge_Contract.Extentions; +using North_Bridge_Contract.Infrastructure; + +namespace North_Bridge_Contract.DataModels; + +public class SaleDataModel : IValidation +{ + public string Id { get; private set; } + + public string WorkerId { get; private set; } + + public DateTime SaleDate { get; private set; } + + public double Sum { get; private set; } + + public bool IsCansel { get; private set; } + + public List Products { get; private set; } + + public SaleDataModel(string id, string workerId, DateTime saleDate, double sum, bool isCansel, List products) + { + Id = id; + WorkerId = workerId; + SaleDate = saleDate; + Sum = sum; + IsCansel = isCansel; + Products = 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 (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/North_Bridge/North_Bridge_Contract/DataModels/WorkerDataModelcs.cs b/North_Bridge/North_Bridge_Contract/DataModels/WorkerDataModelcs.cs new file mode 100644 index 0000000..687d440 --- /dev/null +++ b/North_Bridge/North_Bridge_Contract/DataModels/WorkerDataModelcs.cs @@ -0,0 +1,56 @@ +using North_Bridge_Contract.Exceptions; +using North_Bridge_Contract.Extentions; +using North_Bridge_Contract.Infrastructure; +namespace North_Bridge_Contract.DataModels; + +public class WorkerDataModelcs : IValidation +{ + public string Id { get; private set; } + + public string FIO { get; private set; } + + public string PostId { get; private set; } + + public DateTime BirthDate { get; private set; } + + public DateTime EmploymentDate { get; private set; } + + public bool IsDeleted { get; private set; } + + public WorkerDataModelcs(string id, string fio, string postId, DateTime birthDate, DateTime employmentDate, bool isDeleted) + { + Id = id; + FIO = fio; + PostId = postId; + BirthDate = birthDate; + EmploymentDate = employmentDate; + IsDeleted = 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()})"); + } +} \ No newline at end of file diff --git a/North_Bridge/North_Bridge_Contract/Enums/PostType.cs b/North_Bridge/North_Bridge_Contract/Enums/PostType.cs new file mode 100644 index 0000000..2ad48fd --- /dev/null +++ b/North_Bridge/North_Bridge_Contract/Enums/PostType.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace North_Bridge_Contract.Enums; + +public enum PostType +{ + None = 0, + Supervisor = 1, + Cashier = 2, + Loader = 3, + Consultant = 4 +} diff --git a/North_Bridge/North_Bridge_Contract/Enums/ProductType.cs b/North_Bridge/North_Bridge_Contract/Enums/ProductType.cs new file mode 100644 index 0000000..247bf66 --- /dev/null +++ b/North_Bridge/North_Bridge_Contract/Enums/ProductType.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace North_Bridge_Contract.Enums; + +[Flags] +public enum ProductType +{ + None = 0, + SystemUnit = 1, + Monitor = 2, + ComputerMouse = 4, + AudioSystem = 8 +} diff --git a/North_Bridge/North_Bridge_Contract/Exceptions/ValidationException.cs b/North_Bridge/North_Bridge_Contract/Exceptions/ValidationException.cs new file mode 100644 index 0000000..f5670c6 --- /dev/null +++ b/North_Bridge/North_Bridge_Contract/Exceptions/ValidationException.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace North_Bridge_Contract.Exceptions; + +public class ValidationException : Exception +{ + public ValidationException(string message) : base(message) + { + + } +} diff --git a/North_Bridge/North_Bridge_Contract/Extentions/StringExtentions.cs b/North_Bridge/North_Bridge_Contract/Extentions/StringExtentions.cs new file mode 100644 index 0000000..5f26a74 --- /dev/null +++ b/North_Bridge/North_Bridge_Contract/Extentions/StringExtentions.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace North_Bridge_Contract.Extentions; + +public static class StringExtentions +{ + + public static bool IsEmpty(this string str) + { + return string.IsNullOrWhiteSpace(str); + } + + public static bool IsGuid(this string str) + { + return Guid.TryParse(str, out _); + } +} \ No newline at end of file diff --git a/North_Bridge/North_Bridge_Contract/Infrastructure/IValidation.cs b/North_Bridge/North_Bridge_Contract/Infrastructure/IValidation.cs new file mode 100644 index 0000000..293ba43 --- /dev/null +++ b/North_Bridge/North_Bridge_Contract/Infrastructure/IValidation.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace North_Bridge_Contract.Infrastructure; + +public interface IValidation +{ + void Validate(); +}