2023-04-01 20:27:26 +04:00
|
|
|
|
using BankYouBankruptContracts.BindingModels;
|
|
|
|
|
using BankYouBankruptContracts.ViewModels;
|
|
|
|
|
using BankYouBankruptDataModels.Models;
|
2023-04-01 15:33:39 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2023-04-01 20:27:26 +04:00
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
|
|
|
using System.Diagnostics;
|
2023-04-01 15:33:39 +04:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace BankYouBankruptDatabaseImplement.Models
|
|
|
|
|
{
|
|
|
|
|
public class Account : IAccountModel
|
|
|
|
|
{
|
2023-04-01 20:27:26 +04:00
|
|
|
|
public int Id { get; set; }
|
2023-04-01 15:33:39 +04:00
|
|
|
|
|
2023-04-01 20:27:26 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public string AccountNumber { get; set; } = string.Empty;
|
2023-04-01 15:33:39 +04:00
|
|
|
|
|
2023-04-01 20:27:26 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public int CashierId { get; set; }
|
2023-04-01 15:33:39 +04:00
|
|
|
|
|
2023-04-01 20:27:26 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public int ClientId { get; set; }
|
2023-04-01 15:33:39 +04:00
|
|
|
|
|
2023-04-01 20:49:00 +04:00
|
|
|
|
//для передачи ФИО клиента
|
2023-05-14 18:27:41 +04:00
|
|
|
|
public virtual Client Client { get; set; }
|
2023-04-01 20:49:00 +04:00
|
|
|
|
|
2023-04-01 20:27:26 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public string PasswordAccount { get; set; } = string.Empty;
|
2023-04-01 15:33:39 +04:00
|
|
|
|
|
2023-04-01 20:27:26 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public double Balance { get; set; }
|
2023-04-01 15:33:39 +04:00
|
|
|
|
|
2023-04-01 20:27:26 +04:00
|
|
|
|
[Required]
|
|
|
|
|
public DateTime DateOpen { get; set; } = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
//для реализации связи один ко многим со Снятием наличных
|
|
|
|
|
[ForeignKey("AccountId")]
|
|
|
|
|
public virtual List<CashWithdrawal> CashWithdrawals { get; set; } = new();
|
|
|
|
|
|
|
|
|
|
//для реализации связи один ко многим с Переводом денег
|
2023-05-16 21:23:43 +04:00
|
|
|
|
[NotMapped]
|
2023-04-01 20:27:26 +04:00
|
|
|
|
[ForeignKey("AccountSenderId")]
|
|
|
|
|
public virtual List<MoneyTransfer> MoneyTransferSenders { get; set; } = new();
|
|
|
|
|
|
2023-05-16 21:23:43 +04:00
|
|
|
|
[NotMapped]
|
2023-04-01 20:27:26 +04:00
|
|
|
|
[ForeignKey("AccountPayeeId")]
|
|
|
|
|
public virtual List<MoneyTransfer> MoneyTransferPayees { get; set; } = new();
|
|
|
|
|
|
2023-04-01 20:49:00 +04:00
|
|
|
|
//для реализации связи один ко многим с Картами
|
|
|
|
|
[ForeignKey("AccountId")]
|
|
|
|
|
public virtual List<Card> Cards { get; set; } = new();
|
|
|
|
|
|
2023-04-01 20:27:26 +04:00
|
|
|
|
public static Account Create(BankYouBancruptDatabase context, AccountBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
return new Account()
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
|
|
|
|
ClientId = model.ClientId,
|
2023-05-14 18:27:41 +04:00
|
|
|
|
Client = context.Clients.First(x => x.Id == model.ClientId),
|
2023-04-01 20:27:26 +04:00
|
|
|
|
PasswordAccount = model.PasswordAccount,
|
|
|
|
|
Balance = model.Balance,
|
|
|
|
|
DateOpen = model.DateOpen,
|
|
|
|
|
CashierId = model.CashierId,
|
|
|
|
|
AccountNumber = model.AccountNumber
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update(AccountBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
Balance = model.Balance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public AccountViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
Id = Id,
|
|
|
|
|
CashierId = CashierId,
|
|
|
|
|
ClientId = ClientId,
|
2023-05-14 14:33:49 +04:00
|
|
|
|
Name = Client.Name,
|
|
|
|
|
Patronymic = Client.Patronymic,
|
2023-04-01 20:27:26 +04:00
|
|
|
|
AccountNumber = AccountNumber,
|
|
|
|
|
Balance = Balance,
|
|
|
|
|
PasswordAccount = PasswordAccount,
|
|
|
|
|
DateOpen = DateOpen
|
|
|
|
|
};
|
|
|
|
|
}
|
2023-04-01 15:33:39 +04:00
|
|
|
|
}
|