85 lines
2.7 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BankContracts.ViewModels.Cashier.ViewModels;
using BankContracts.BindingModels.Cashier;
using BankDataModels.Models.Cashier;
namespace BankDatabaseImplement.Models.Cashier
{
public class Cashier : ICashierModel
{
public int Id { get; set; }
[Required]
public string Password { get; set; } = string.Empty;
[Required]
public string Name { get; set; } = string.Empty;
[Required]
public string Surname { get; set; } = string.Empty;
[Required]
public string Patronymic { get; set; } = string.Empty;
[Required]
public string Email { get; set; } = string.Empty;
[Required]
public string MobilePhone { get; set; } = string.Empty;
//для реализации связи один ко многим со Счётом
[ForeignKey("CashierId")]
public virtual List<Account> Accounts { get; set; } = new();
//для реализации связи один ко многим с заявками на снятие наличных со счёта
[ForeignKey("CashierId")]
public virtual List<CashWithdrawal> CashWithdrawals { get; set; } = new();
//для реализации связи один ко многим с заявками на переводы денег
[ForeignKey("CashierId")]
public virtual List<MoneyTransfer> MoneyTransfers { get; set; } = new();
public static Cashier Create(BankDatabase context, CashierBindingModel model)
{
return new Cashier()
{
Id = model.Id,
Name = model.Name,
Surname = model.Surname,
Patronymic = model.Patronymic,
Email = model.Email,
MobilePhone = model.MobilePhone,
Password = model.Password
};
}
public void Update(CashierBindingModel model)
{
Id = model.Id;
Name = model.Name;
Surname = model.Surname;
Patronymic = model.Patronymic;
Email = model.Email;
MobilePhone = model.MobilePhone;
Password = model.Password;
}
public CashierViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
Surname = Surname,
Patronymic = Patronymic,
Email = Email,
MobilePhone = MobilePhone,
Password = Password
};
}
}