feat: первая версия дата моделек

This commit is contained in:
2025-04-18 15:11:59 +04:00
parent 998c1e5d33
commit 712da770e5
7 changed files with 369 additions and 0 deletions

View 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 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");
}
}
}

View File

@@ -0,0 +1,37 @@
using BankContracts.Exceptions;
using BankContracts.Extensions;
using BankContracts.Infrastructure;
namespace BankContracts.DataModels;
/// <summary>
/// Дата модель клиент кредитная программа
/// </summary>
/// <param name="clientId"></param>
/// <param name="creditProgramId"></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");
}
}
}

View 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");
}
}
}

View 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");
}
}
}

View 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");
}
}
}

View 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");
}
}
}

View 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");
}
}
}