101 lines
3.5 KiB
C#
101 lines
3.5 KiB
C#
using BankDataModels.Models;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using BankContracts.BindingModels;
|
|
using BankContracts.ViewModels;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace BankDatabaseImplement.Models
|
|
{
|
|
public class Client : IClientModel
|
|
{
|
|
public string Snils { get; set; } = string.Empty;
|
|
[Required]
|
|
public string ClientSurname { get; set; } = string.Empty;
|
|
[Required]
|
|
public string ClientName { get; set; } = string.Empty;
|
|
[Required]
|
|
public string ClientPatronymic { get; set; } = string.Empty;
|
|
[Required]
|
|
public string Phone { get; set; } = string.Empty;
|
|
public string Email { get; set; } = string.Empty;
|
|
[Required]
|
|
public string PasswordHash { get; set; } = string.Empty;
|
|
[Required]
|
|
public int WorkerId { get; set; }
|
|
public virtual Worker Worker { get; set; } = null!;
|
|
public virtual List<ClientProgram> ClientPrograms { get; set; } = null!;
|
|
public virtual List<ClientDeposit> ClientDeposits { get; set; } = null!;
|
|
//[NotMapped]
|
|
//public Dictionary<int, IProgramModel> ClientPrograms
|
|
//{
|
|
// get
|
|
// {
|
|
// if (_clientPrograms == null)
|
|
// {
|
|
// _clientPrograms = Programs.ToDictionary(
|
|
// x => x.ProgramId,
|
|
// x => (x.Program as IProgramModel)
|
|
// );
|
|
// }
|
|
// return _clientPrograms;
|
|
// }
|
|
//}
|
|
//[NotMapped]
|
|
//public Dictionary<int, IDepositModel> ClientDeposits
|
|
//{
|
|
// get
|
|
// {
|
|
// if (_clientDeposits == null)
|
|
// {
|
|
// _clientDeposits = Deposits.ToDictionary(
|
|
// x => x.DepositId,
|
|
// x => (x.Deposit as IDepositModel)
|
|
// );
|
|
// }
|
|
// return _clientDeposits;
|
|
// }
|
|
//}
|
|
public static Client? Create(ClientBindingModel model)
|
|
{
|
|
if (model == null)
|
|
return null;
|
|
return new Client
|
|
{
|
|
Snils = model.Snils,
|
|
ClientSurname = model.ClientSurname,
|
|
ClientName = model.ClientName,
|
|
ClientPatronymic = model.ClientPatronymic,
|
|
Phone = model.Phone,
|
|
Email = model.Email ?? string.Empty,
|
|
PasswordHash = model.PasswordHash,
|
|
WorkerId = model.WorkerId,
|
|
};
|
|
}
|
|
public void Update(ClientBindingModel model)
|
|
{
|
|
if (model == null)
|
|
return;
|
|
Snils = model.Snils;
|
|
ClientSurname = model.ClientSurname;
|
|
ClientName = model.ClientName;
|
|
ClientPatronymic = model.ClientPatronymic;
|
|
Phone = model.Phone;
|
|
Email = model.Email ?? string.Empty;
|
|
PasswordHash = model.PasswordHash;
|
|
WorkerId = model.WorkerId;
|
|
}
|
|
public ClientViewModel GetViewModel => new()
|
|
{
|
|
Snils = Snils,
|
|
ClientSurname = ClientSurname,
|
|
ClientName = ClientName,
|
|
ClientPatronymic = ClientPatronymic,
|
|
Phone = Phone,
|
|
Email = Email ?? string.Empty,
|
|
PasswordHash = PasswordHash,
|
|
WorkerId = WorkerId,
|
|
};
|
|
}
|
|
}
|