Merge pull request 'Первый Task, дата модели' (#1) from Task_1_Models into main
Reviewed-on: #1
This commit was merged in pull request #1.
This commit is contained in:
9
TheBank/BankContracts/BankContracts.csproj
Normal file
9
TheBank/BankContracts/BankContracts.csproj
Normal file
@@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
84
TheBank/BankContracts/DataModels/ClerkDataModel.cs
Normal file
84
TheBank/BankContracts/DataModels/ClerkDataModel.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using BankContracts.Exceptions;
|
||||
using BankContracts.Extensions;
|
||||
using BankContracts.Infrastructure;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace BankContracts.DataModels;
|
||||
|
||||
/// <summary>
|
||||
/// Дата модель клерка
|
||||
/// </summary>
|
||||
/// <param name="id">уникальный Guid индентификатор</param>
|
||||
/// <param name="name">имя</param>
|
||||
/// <param name="surname">фамилия</param>
|
||||
/// <param name="middleName">отчество</param>
|
||||
/// <param name="login">логин</param>
|
||||
/// <param name="password">пароль</param>
|
||||
/// <param name="email">адрес электронной почты</param>
|
||||
/// <param name="phoneNumber">номер телефона</param>
|
||||
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 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using BankContracts.Exceptions;
|
||||
using BankContracts.Extensions;
|
||||
using BankContracts.Infrastructure;
|
||||
|
||||
namespace BankContracts.DataModels;
|
||||
|
||||
/// <summary>
|
||||
/// Дата модель клиент кредитная программа
|
||||
/// </summary>
|
||||
/// <param name="clientId">уникальный Guid индентификатор клиента</param>
|
||||
/// <param name="creditProgramId">уникальный Guid индентификатор кредитной программы</param>
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
58
TheBank/BankContracts/DataModels/ClientDataModel.cs
Normal file
58
TheBank/BankContracts/DataModels/ClientDataModel.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using BankContracts.Exceptions;
|
||||
using BankContracts.Extensions;
|
||||
using BankContracts.Infrastructure;
|
||||
|
||||
namespace BankContracts.DataModels;
|
||||
|
||||
/// <summary>
|
||||
/// Дата модель клиента
|
||||
/// </summary>
|
||||
/// <param name="id">уникальный Guid индентификатор</param>
|
||||
/// <param name="name">имя клиента</param>
|
||||
/// <param name="surname">фамилия клиента</param>
|
||||
/// <param name="balance">баланс клиента</param>
|
||||
/// <param name="clerkId">уникальный Guid индентификатор клерка</param>
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using BankContracts.Exceptions;
|
||||
using BankContracts.Extensions;
|
||||
using BankContracts.Infrastructure;
|
||||
|
||||
namespace BankContracts.DataModels;
|
||||
|
||||
/// <summary>
|
||||
/// Дата модель кредитная программа - валюта (многие ко многим)
|
||||
/// </summary>
|
||||
/// <param name="creditProgramId">уникальный Guid индентификатор кредитной программы</param>
|
||||
/// <param name="currencyId">уникальный Guid индентификатор валюты</param>
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
69
TheBank/BankContracts/DataModels/CreditProgramDataModel.cs
Normal file
69
TheBank/BankContracts/DataModels/CreditProgramDataModel.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using BankContracts.Exceptions;
|
||||
using BankContracts.Extensions;
|
||||
using BankContracts.Infrastructure;
|
||||
|
||||
namespace BankContracts.DataModels;
|
||||
|
||||
/// <summary>
|
||||
/// Дата модель кредитной программы
|
||||
/// </summary>
|
||||
/// <param name="id">уникальный Guid индентификатор</param>
|
||||
/// <param name="name">название</param>
|
||||
/// <param name="cost">сумма</param>
|
||||
/// <param name="maxCost">максимальная сумма</param>
|
||||
/// <param name="storekeeperId">уникальный Guid Индентификатор кладовщика</param>
|
||||
/// <param name="periodId">уникальный Guid Индентификатор срока</param>
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
58
TheBank/BankContracts/DataModels/CurrencyDataModel.cs
Normal file
58
TheBank/BankContracts/DataModels/CurrencyDataModel.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using BankContracts.Exceptions;
|
||||
using BankContracts.Extensions;
|
||||
using BankContracts.Infrastructure;
|
||||
|
||||
namespace BankContracts.DataModels;
|
||||
|
||||
/// <summary>
|
||||
/// Дата модель валюты
|
||||
/// </summary>
|
||||
/// <param name="id">уникальный Guid индентификатор</param>
|
||||
/// <param name="name">название</param>
|
||||
/// <param name="abbreviation">аббревиатура</param>
|
||||
/// <param name="cost">стоимость валюты</param>
|
||||
/// <param name="storekeeperId">уникальный Guid Индентификатор кладовщика</param>
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
37
TheBank/BankContracts/DataModels/DepositClientDataModel.cs
Normal file
37
TheBank/BankContracts/DataModels/DepositClientDataModel.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using BankContracts.Exceptions;
|
||||
using BankContracts.Extensions;
|
||||
using BankContracts.Infrastructure;
|
||||
|
||||
namespace BankContracts.DataModels;
|
||||
|
||||
/// <summary>
|
||||
/// Дата модель вклад клиент
|
||||
/// </summary>
|
||||
/// <param name="depositId">уникальный Guid индентификатор вклада</param>
|
||||
/// <param name="clientId">уникальный Guid индентификатор клиента</param>
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
37
TheBank/BankContracts/DataModels/DepositCurrencyDataModel.cs
Normal file
37
TheBank/BankContracts/DataModels/DepositCurrencyDataModel.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using BankContracts.Exceptions;
|
||||
using BankContracts.Extensions;
|
||||
using BankContracts.Infrastructure;
|
||||
|
||||
namespace BankContracts.DataModels;
|
||||
|
||||
/// <summary>
|
||||
/// Дата модель вклад валюта
|
||||
/// </summary>
|
||||
/// <param name="depositId">уникальный Guid индентификатор вклада</param>
|
||||
/// <param name="currencyId">уникальный Guid индентификатор валюты</param>
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
58
TheBank/BankContracts/DataModels/DepositDataModel.cs
Normal file
58
TheBank/BankContracts/DataModels/DepositDataModel.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using BankContracts.Exceptions;
|
||||
using BankContracts.Extensions;
|
||||
using BankContracts.Infrastructure;
|
||||
|
||||
namespace BankContracts.DataModels;
|
||||
|
||||
/// <summary>
|
||||
/// Дата модель вклада
|
||||
/// </summary>
|
||||
/// <param name="id">уникальный Guid индентификатор</param>
|
||||
/// <param name="interestRate">процентная ставка</param>
|
||||
/// <param name="cost">стоимость</param>
|
||||
/// <param name="period">срок</param>
|
||||
/// <param name="clerkId">уникальный Guid индентификатор клерка</param>
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
47
TheBank/BankContracts/DataModels/PeriodDataModel.cs
Normal file
47
TheBank/BankContracts/DataModels/PeriodDataModel.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using BankContracts.Exceptions;
|
||||
using BankContracts.Extensions;
|
||||
using BankContracts.Infrastructure;
|
||||
|
||||
namespace BankContracts.DataModels;
|
||||
|
||||
/// <summary>
|
||||
/// Дата модель срока
|
||||
/// </summary>
|
||||
/// <param name="id">уникальный Guid индентификатор</param>
|
||||
/// <param name="startDate">дата начала</param>
|
||||
/// <param name="endDate">дата окончания</param>
|
||||
/// <param name="storekeeperId">уникальный Guid индентификатор кладовщика</param>
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
58
TheBank/BankContracts/DataModels/ReplenishmentDataModel.cs
Normal file
58
TheBank/BankContracts/DataModels/ReplenishmentDataModel.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using BankContracts.Exceptions;
|
||||
using BankContracts.Extensions;
|
||||
using BankContracts.Infrastructure;
|
||||
|
||||
namespace BankContracts.DataModels;
|
||||
|
||||
/// <summary>
|
||||
/// Дата модель пополнения
|
||||
/// </summary>
|
||||
/// <param name="id">уникальный Guid индентификатор</param>
|
||||
/// <param name="amount">сумма пополнения</param>
|
||||
/// <param name="date">дата пополнения</param>
|
||||
/// <param name="depositId">уникальный Guid индентификатор вклада</param>
|
||||
/// <param name="clerkId">уникальный Guid индентификатор клерка</param>
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
86
TheBank/BankContracts/DataModels/StorekeeperDataModel.cs
Normal file
86
TheBank/BankContracts/DataModels/StorekeeperDataModel.cs
Normal file
@@ -0,0 +1,86 @@
|
||||
using BankContracts.Exceptions;
|
||||
using BankContracts.Extensions;
|
||||
using BankContracts.Infrastructure;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace BankContracts.DataModels;
|
||||
|
||||
/// <summary>
|
||||
/// Дата модель кладовщика
|
||||
/// </summary>
|
||||
/// <param name="id">уникальный Guid индентификатор</param>
|
||||
/// <param name="name">имя</param>
|
||||
/// <param name="surname">фамилия</param>
|
||||
/// <param name="middleName">отчество (лучше не придумал)</param>
|
||||
/// <param name="login">логин</param>
|
||||
/// <param name="password">пароль</param>
|
||||
/// <param name="email">адрес электронной почты</param>
|
||||
/// <param name="phoneNumber">номер телефона</param>
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
6
TheBank/BankContracts/Exceptions/ValidationException.cs
Normal file
6
TheBank/BankContracts/Exceptions/ValidationException.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace BankContracts.Exceptions;
|
||||
|
||||
/// <summary>
|
||||
/// Класс-исключение при валидации данных в дата моделях
|
||||
/// </summary>
|
||||
public class ValidationException(string message) : Exception(message) { }
|
||||
17
TheBank/BankContracts/Extensions/StringExtension.cs
Normal file
17
TheBank/BankContracts/Extensions/StringExtension.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
namespace BankContracts.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Класс расширение для string
|
||||
/// </summary>
|
||||
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 _);
|
||||
}
|
||||
}
|
||||
9
TheBank/BankContracts/Infrastructure/IValidation.cs
Normal file
9
TheBank/BankContracts/Infrastructure/IValidation.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace BankContracts.Infrastructure;
|
||||
|
||||
/// <summary>
|
||||
/// Валидация данных в дата моделях
|
||||
/// </summary>
|
||||
internal interface IValidation
|
||||
{
|
||||
void Validate();
|
||||
}
|
||||
22
TheBank/TheBank.sln
Normal file
22
TheBank/TheBank.sln
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user