diff --git a/TheBank/BankContracts/DataModels/ClerkDataModel.cs b/TheBank/BankContracts/DataModels/ClerkDataModel.cs new file mode 100644 index 0000000..a1fc55a --- /dev/null +++ b/TheBank/BankContracts/DataModels/ClerkDataModel.cs @@ -0,0 +1,84 @@ +using BankContracts.Exceptions; +using BankContracts.Extensions; +using BankContracts.Infrastructure; +using System.Text.RegularExpressions; + +namespace BankContracts.DataModels; + +/// +/// Дата модель клерка +/// +/// уникальный Guid индентификатор +/// имя +/// фамилия +/// отчество +/// логин +/// пароль +/// адрес электронной почты +/// номер телефона +public class ClerkDataModel(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 Login is null or empty"); + } + if (Email.IsEmpty()) + { + throw new ValidationException("Field Login 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 Login 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/DataModels/ClientCreditProgramDataModel.cs b/TheBank/BankContracts/DataModels/ClientCreditProgramDataModel.cs new file mode 100644 index 0000000..3b140dd --- /dev/null +++ b/TheBank/BankContracts/DataModels/ClientCreditProgramDataModel.cs @@ -0,0 +1,37 @@ +using BankContracts.Exceptions; +using BankContracts.Extensions; +using BankContracts.Infrastructure; + +namespace BankContracts.DataModels; + +/// +/// Дата модель клиент кредитная программа +/// +/// +/// +public class ClientCreditProgramDataModel(string clientId, string creditProgramId) : IValidation +{ + public string ClientId { get; private set; } = clientId; + + public string CreditProgramId { get; private set; } = creditProgramId; + + public void Validate() + { + if (ClientId.IsEmpty()) + { + throw new ValidationException("Field ClientId is null or empty"); + } + if (!ClientId.IsGuid()) + { + throw new ValidationException("The value in the field ClientId is not a unique identifier"); + } + 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"); + } + } +} diff --git a/TheBank/BankContracts/DataModels/ClientDataModel.cs b/TheBank/BankContracts/DataModels/ClientDataModel.cs new file mode 100644 index 0000000..bcff9c5 --- /dev/null +++ b/TheBank/BankContracts/DataModels/ClientDataModel.cs @@ -0,0 +1,58 @@ +using BankContracts.Exceptions; +using BankContracts.Extensions; +using BankContracts.Infrastructure; + +namespace BankContracts.DataModels; + +/// +/// Дата модель клиента +/// +/// уникальный Guid индентификатор +/// имя клиента +/// фамилия клиента +/// баланс клиента +/// уникальный Guid индентификатор клерка +public class ClientDataModel(string id, string name, string surname, decimal balance, string clerkId) : IValidation +{ + public string Id { get; private set; } = id; + + public string Name { get; private set; } = name; + + public string Surname { get; private set; } = surname; + + public decimal Balance { get; private set; } = balance; + + public string Clerkid { get; private set; } = clerkId; + + 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 (Balance <= 0) + { + throw new ValidationException("Field Balance is less or equal to zero"); + } + if (Clerkid.IsEmpty()) + { + throw new ValidationException("Field Clerkid is null or empty"); + } + if (!Clerkid.IsGuid()) + { + throw new ValidationException("The value in the field Clerkid is not a unique identifier"); + } + } +} diff --git a/TheBank/BankContracts/DataModels/DepositClientDataModel.cs b/TheBank/BankContracts/DataModels/DepositClientDataModel.cs new file mode 100644 index 0000000..2159e31 --- /dev/null +++ b/TheBank/BankContracts/DataModels/DepositClientDataModel.cs @@ -0,0 +1,37 @@ +using BankContracts.Exceptions; +using BankContracts.Extensions; +using BankContracts.Infrastructure; + +namespace BankContracts.DataModels; + +/// +/// Дата модель вклад клиент +/// +/// уникальный Guid индентификатор вклада +/// уникальный Guid индентификатор клиента +public class DepositClientDataModel(string depositId, string clientId) : IValidation +{ + public string DepositId { get; private set; } = depositId; + + public string ClientId { get; private set; } = clientId; + + public void Validate() + { + if (DepositId.IsEmpty()) + { + throw new ValidationException("Field DepositId is null or empty"); + } + if (!DepositId.IsGuid()) + { + throw new ValidationException("The value in the field DepositId is not a unique identifier"); + } + if (ClientId.IsEmpty()) + { + throw new ValidationException("Field ClientId is null or empty"); + } + if (!ClientId.IsGuid()) + { + throw new ValidationException("The value in the field ClientId is not a unique identifier"); + } + } +} diff --git a/TheBank/BankContracts/DataModels/DepositCurrencyDataModel.cs b/TheBank/BankContracts/DataModels/DepositCurrencyDataModel.cs new file mode 100644 index 0000000..ace234b --- /dev/null +++ b/TheBank/BankContracts/DataModels/DepositCurrencyDataModel.cs @@ -0,0 +1,37 @@ +using BankContracts.Exceptions; +using BankContracts.Extensions; +using BankContracts.Infrastructure; + +namespace BankContracts.DataModels; + +/// +/// Дата модель вклад валюта +/// +/// уникальный Guid индентификатор вклада +/// уникальный Guid индентификатор валюты +public class DepositCurrencyDataModel(string depositId, string currencyId) : IValidation +{ + public string DepositId { get; private set; } = depositId; + + public string CurrencyId { get; private set; } = currencyId; + + public void Validate() + { + if (DepositId.IsEmpty()) + { + throw new ValidationException("Field DepositId is null or empty"); + } + if (!DepositId.IsGuid()) + { + throw new ValidationException("The value in the field DepositId 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/DepositDataModel.cs b/TheBank/BankContracts/DataModels/DepositDataModel.cs new file mode 100644 index 0000000..7dbcc47 --- /dev/null +++ b/TheBank/BankContracts/DataModels/DepositDataModel.cs @@ -0,0 +1,58 @@ +using BankContracts.Exceptions; +using BankContracts.Extensions; +using BankContracts.Infrastructure; + +namespace BankContracts.DataModels; + +/// +/// Дата модель вклада +/// +/// уникальный Guid индентификатор +/// процентная ставка +/// стоимость +/// срок +/// уникальный Guid индентификатор клерка +public class DepositDataModel(string id, float interestRate, decimal cost, int period, string clerkId) : IValidation +{ + public string Id { get; private set; } = id; + + public float InterestRate { get; private set; } = interestRate; + + public decimal Cost { get; private set; } = cost; + + public int Period { get; private set; } = period; + + public string ClerkId { get; private set; } = clerkId; + + 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 (InterestRate <= 0) + { + throw new ValidationException("Field InterestRate is less or equal to zero"); + } + if (Cost <= 0) + { + throw new ValidationException("Field Cost is less or equal to zero"); + } + if (Period <= 0) + { + throw new ValidationException("Field Period is less or equal to zero"); + } + if (ClerkId.IsEmpty()) + { + throw new ValidationException("Field ClerkId is null or empty"); + } + if (!ClerkId.IsGuid()) + { + throw new ValidationException("The value in the field ClerkId is not a unique identifier"); + } + } +} diff --git a/TheBank/BankContracts/DataModels/ReplenishmentDataModel.cs b/TheBank/BankContracts/DataModels/ReplenishmentDataModel.cs new file mode 100644 index 0000000..dfa85fa --- /dev/null +++ b/TheBank/BankContracts/DataModels/ReplenishmentDataModel.cs @@ -0,0 +1,58 @@ +using BankContracts.Exceptions; +using BankContracts.Extensions; +using BankContracts.Infrastructure; + +namespace BankContracts.DataModels; + +/// +/// Дата модель пополнения +/// +/// уникальный Guid индентификатор +/// сумма пополнения +/// дата пополнения +/// уникальный Guid индентификатор вклада +/// уникальный Guid индентификатор клерка +public class ReplenishmentDataModel(string id, decimal amount, DateTime date, string depositId, string clerkId) : IValidation +{ + public string Id { get; private set; } = id; + + public decimal Amount { get; private set; } = amount; + + public DateTime Date { get; private set; } = date; + + public string DepositId { get; private set; } = depositId; + + public string ClerkId { get; private set; } = clerkId; + + 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 (Amount <= 0) + { + throw new ValidationException("Field Amount is less or equal to zero"); + } + if (DepositId.IsEmpty()) + { + throw new ValidationException("Field DepositId is null or empty"); + } + if (!DepositId.IsGuid()) + { + throw new ValidationException("The value in the field DepositId is not a unique identifier"); + } + if (ClerkId.IsEmpty()) + { + throw new ValidationException("Field ClerkId is null or empty"); + } + if (!ClerkId.IsGuid()) + { + throw new ValidationException("The value in the field ClerkId is not a unique identifier"); + } + } +}