diff --git a/TheBank/BankContracts/BankContracts.csproj b/TheBank/BankContracts/BankContracts.csproj new file mode 100644 index 0000000..125f4c9 --- /dev/null +++ b/TheBank/BankContracts/BankContracts.csproj @@ -0,0 +1,9 @@ + + + + net9.0 + enable + enable + + + diff --git a/TheBank/BankContracts/DataModels/CreditProgramCurrencyDataModel.cs b/TheBank/BankContracts/DataModels/CreditProgramCurrencyDataModel.cs new file mode 100644 index 0000000..2b24480 --- /dev/null +++ b/TheBank/BankContracts/DataModels/CreditProgramCurrencyDataModel.cs @@ -0,0 +1,37 @@ +using BankContracts.Exceptions; +using BankContracts.Extensions; +using BankContracts.Infrastructure; + +namespace BankContracts.DataModels; + +/// +/// Дата модель кредитная программа - валюта (многие ко многим) +/// +/// уникальный Guid индентификатор кредитной программы +/// уникальный Guid индентификатор валюты +public class CreditProgramCurrencyDataModel(string creditProgramId, string currencyId) : IValidation +{ + public string CreditProgramId { get; private set; } = creditProgramId; + + public string CurrencyId { get; private set; } = currencyId; + + public void Validate() + { + if (CreditProgramId.IsEmpty()) + { + throw new ValidationException("Field CreditProgramId is null or empty"); + } + if (!CreditProgramId.IsGuid()) + { + throw new ValidationException("The value in the field CreditProgramId is not a unique identifier"); + } + if (CurrencyId.IsEmpty()) + { + throw new ValidationException("Field CurrencyId is null or empty"); + } + if (!CurrencyId.IsGuid()) + { + throw new ValidationException("The value in the field CurrencyId is not a unique identifier"); + } + } +} diff --git a/TheBank/BankContracts/DataModels/CreditProgramDataModel.cs b/TheBank/BankContracts/DataModels/CreditProgramDataModel.cs new file mode 100644 index 0000000..e7ee5af --- /dev/null +++ b/TheBank/BankContracts/DataModels/CreditProgramDataModel.cs @@ -0,0 +1,69 @@ +using BankContracts.Exceptions; +using BankContracts.Extensions; +using BankContracts.Infrastructure; + +namespace BankContracts.DataModels; + +/// +/// Дата модель кредитной программы +/// +/// уникальный Guid индентификатор +/// название +/// сумма +/// максимальная сумма +/// уникальный Guid Индентификатор кладовщика +/// уникальный Guid Индентификатор срока +public class CreditProgramDataModel(string id, string name, decimal cost, decimal maxCost, string storekeeperId, string periodId) : IValidation +{ + public string Id { get; private set; } = id; + + public string Name { get; private set; } = name; + + public decimal Cost { get; private set; } = cost; + + public decimal MaxCost { get; private set; } = maxCost; + + public string StorekeeperId { get; private set; } = storekeeperId; + + public string PeriodId { get; private set; } = periodId; + + public void Validate() + { + if (Id.IsEmpty()) + { + throw new ValidationException("Field Id is null or empty"); + } + if (!Id.IsGuid()) + { + throw new ValidationException("The value in the field Id is not a unique identifier"); + } + if (Name.IsEmpty()) + { + throw new ValidationException("Field Name is null or empty"); + } + if (Cost <= 0) + { + throw new ValidationException("Field Cost is less or equal to zero"); + } + if (MaxCost <= 0) + { + throw new ValidationException("Field MaxCost is less or equal to zero"); + } + if (StorekeeperId.IsEmpty()) + { + throw new ValidationException("Field StorekeeperId is null or empty"); + } + if (!StorekeeperId.IsGuid()) + { + throw new ValidationException("The value in the field StorekeeperId is not a unique identifier"); + } + if (PeriodId.IsEmpty()) + { + throw new ValidationException("Field PeriodId is null or empty"); + } + if (!PeriodId.IsGuid()) + { + throw new ValidationException("The value in the field PeriodId is not a unique identifier"); + } + } +} diff --git a/TheBank/BankContracts/DataModels/CurrencyDataModel.cs b/TheBank/BankContracts/DataModels/CurrencyDataModel.cs new file mode 100644 index 0000000..3a2bd50 --- /dev/null +++ b/TheBank/BankContracts/DataModels/CurrencyDataModel.cs @@ -0,0 +1,58 @@ +using BankContracts.Exceptions; +using BankContracts.Extensions; +using BankContracts.Infrastructure; + +namespace BankContracts.DataModels; + +/// +/// Дата модель валюты +/// +/// уникальный Guid индентификатор +/// название +/// аббревиатура +/// стоимость валюты +/// уникальный Guid Индентификатор кладовщика +public class CurrencyDataModel(string id, string name, string abbreviation, decimal cost, string storekeeperId) : IValidation +{ + public string Id { get; private set; } = id; + + public string Name { get; private set; } = name; + + public string Abbreviation { get; private set; } = abbreviation; + + public decimal Cost { get; private set; } = cost; + + public string StorekeeperId { get; private set; } = storekeeperId; + + public void Validate() + { + if (Id.IsEmpty()) + { + throw new ValidationException("Field Id is null or empty"); + } + if (!Id.IsGuid()) + { + throw new ValidationException("The value in the field Id is not a unique identifier"); + } + if (Name.IsEmpty()) + { + throw new ValidationException("Field Name is null or empty"); + } + if (Abbreviation.IsEmpty()) + { + throw new ValidationException("Field Abbreviation is null or empty"); + } + if (Cost <= 0) + { + throw new ValidationException("Field Cost is less or equal to zero"); + } + if (StorekeeperId.IsEmpty()) + { + throw new ValidationException("Field StorekeeperId is null or empty"); + } + if (!StorekeeperId.IsGuid()) + { + throw new ValidationException("The value in the field StorekeeperId is not a unique identifier"); + } + } +} diff --git a/TheBank/BankContracts/DataModels/PeriodDataModel.cs b/TheBank/BankContracts/DataModels/PeriodDataModel.cs new file mode 100644 index 0000000..cfe9f76 --- /dev/null +++ b/TheBank/BankContracts/DataModels/PeriodDataModel.cs @@ -0,0 +1,47 @@ +using BankContracts.Exceptions; +using BankContracts.Extensions; +using BankContracts.Infrastructure; + +namespace BankContracts.DataModels; + +/// +/// Дата модель срока +/// +/// уникальный Guid индентификатор +/// +/// +/// уникальный Guid индентификатор кладовщика +public class PeriodDataModel(string id, DateTime startDate, DateTime endDate, string storekeeperId) : IValidation +{ + public string Id { get; private set; } = id; + + public DateTime StartTime { get; private set; } = startDate; + + public DateTime EndTime { get; private set; } = endDate; + + public string StorekeeperId { get; private set; } = storekeeperId; + + public void Validate() + { + if (Id.IsEmpty()) + { + throw new ValidationException("Field Id is null or empty"); + } + if (!Id.IsGuid()) + { + throw new ValidationException("The value in the field Id is not a unique identifier"); + } + if (StartTime.Date > EndTime.Date) + { + throw new ValidationException($"he date of period start cannot be larger than the date of period end"); + } + if (StorekeeperId.IsEmpty()) + { + throw new ValidationException("Field StorekeeperId is null or empty"); + } + if (!StorekeeperId.IsGuid()) + { + throw new ValidationException("The value in the field StorekeeperId is not a unique identifier"); + } + } +} diff --git a/TheBank/BankContracts/DataModels/StorekeeperDataModel.cs b/TheBank/BankContracts/DataModels/StorekeeperDataModel.cs new file mode 100644 index 0000000..b9a9037 --- /dev/null +++ b/TheBank/BankContracts/DataModels/StorekeeperDataModel.cs @@ -0,0 +1,86 @@ +using BankContracts.Exceptions; +using BankContracts.Extensions; +using BankContracts.Infrastructure; +using System.Text.RegularExpressions; + +namespace BankContracts.DataModels; + +/// +/// Дата модель кладовщика +/// +/// уникальный Guid индентификатор +/// имя +/// фамилия +/// отчество (лучше не придумал) +/// логин +/// пароль +/// адрес электронной почты +/// номер телефона +public class StorekeeperDataModel( + string id, string name, string surname, string middleName, + string login, string password, string email, string phoneNumber) : IValidation +{ + public string Id { get; private set; } = id; + + public string Name { get; private set; } = name; + + public string Surname { get; private set; } = surname; + + public string MiddleName { get; private set; } = middleName; + + public string Login { get; private set; } = login; + + public string Password { get; private set; } = password; + + public string Email { get; private set; } = email; + + public string PhoneNumber { get; private set; } = phoneNumber; + + public void Validate() + { + if (Id.IsEmpty()) + { + throw new ValidationException("Field Id is null or empty"); + } + if (!Id.IsGuid()) + { + throw new ValidationException("The value in the field Id is not a unique identifier"); + } + if (Name.IsEmpty()) + { + throw new ValidationException("Field Name is null or empty"); + } + if (Surname.IsEmpty()) + { + throw new ValidationException("Field Surname is null or empty"); + } + if (MiddleName.IsEmpty()) + { + throw new ValidationException("Field MiddleName is null or empty"); + } + if (Login.IsEmpty()) + { + throw new ValidationException("Field Login is null or empty"); + } + if (Password.IsEmpty()) + { + throw new ValidationException("Field Password is null or empty"); + } + if (Email.IsEmpty()) + { + throw new ValidationException("Field Email is null or empty"); + } + if (!Regex.IsMatch(Email, @"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$")) + { + throw new ValidationException("Field Email is not a valid email address"); + } + if (PhoneNumber.IsEmpty()) + { + throw new ValidationException("Field PhoneNumber is null or empty"); + } + if (!Regex.IsMatch(PhoneNumber, @"^((8|\+7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}$")) + { + throw new ValidationException("Field PhoneNumber is not a phone number"); + } + } +} diff --git a/TheBank/BankContracts/Exceptions/ValidationException.cs b/TheBank/BankContracts/Exceptions/ValidationException.cs new file mode 100644 index 0000000..e167df6 --- /dev/null +++ b/TheBank/BankContracts/Exceptions/ValidationException.cs @@ -0,0 +1,6 @@ +namespace BankContracts.Exceptions; + +/// +/// Класс-исключение при валидации данных в дата моделях +/// +public class ValidationException(string message) : Exception(message) { } \ No newline at end of file diff --git a/TheBank/BankContracts/Extensions/StringExtension.cs b/TheBank/BankContracts/Extensions/StringExtension.cs new file mode 100644 index 0000000..42ad086 --- /dev/null +++ b/TheBank/BankContracts/Extensions/StringExtension.cs @@ -0,0 +1,14 @@ +namespace BankContracts.Extensions; + +public static class StringExtension +{ + public static bool IsEmpty(this string str) + { + return string.IsNullOrWhiteSpace(str); + } + + public static bool IsGuid(this string str) + { + return Guid.TryParse(str, out _); + } +} diff --git a/TheBank/BankContracts/Infrastructure/IValidation.cs b/TheBank/BankContracts/Infrastructure/IValidation.cs new file mode 100644 index 0000000..dfd36f2 --- /dev/null +++ b/TheBank/BankContracts/Infrastructure/IValidation.cs @@ -0,0 +1,9 @@ +namespace BankContracts.Infrastructure; + +/// +/// Валидация данных в дата моделях +/// +internal interface IValidation +{ + void Validate(); +} diff --git a/TheBank/TheBank.sln b/TheBank/TheBank.sln new file mode 100644 index 0000000..afb9ea6 --- /dev/null +++ b/TheBank/TheBank.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.12.35707.178 d17.12 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BankContracts", "BankContracts\BankContracts.csproj", "{7AF1B83C-2E92-482F-8189-6FE7313134FD}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7AF1B83C-2E92-482F-8189-6FE7313134FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7AF1B83C-2E92-482F-8189-6FE7313134FD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7AF1B83C-2E92-482F-8189-6FE7313134FD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7AF1B83C-2E92-482F-8189-6FE7313134FD}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal