CourseWork_BankYouBankrupt/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Account.cs

91 lines
2.5 KiB
C#
Raw Normal View History

using BankYouBankruptContracts.BindingModels;
using BankYouBankruptContracts.ViewModels;
using BankYouBankruptDataModels.Models;
2023-04-01 15:33:39 +04:00
using System;
using System.Collections.Generic;
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
{
public int Id { get; set; }
2023-04-01 15:33:39 +04:00
[Required]
public string AccountNumber { get; set; } = string.Empty;
2023-04-01 15:33:39 +04:00
[Required]
public int CashierId { get; set; }
2023-04-01 15:33:39 +04:00
[Required]
public int ClientId { get; set; }
2023-04-01 15:33:39 +04:00
//для передачи ФИО клиента
2023-05-14 18:27:41 +04:00
public virtual Client Client { get; set; }
[Required]
public string PasswordAccount { get; set; } = string.Empty;
2023-04-01 15:33:39 +04:00
[Required]
public double Balance { get; set; }
2023-04-01 15:33:39 +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]
[ForeignKey("AccountSenderId")]
public virtual List<MoneyTransfer> MoneyTransferSenders { get; set; } = new();
2023-05-16 21:23:43 +04:00
[NotMapped]
[ForeignKey("AccountPayeeId")]
public virtual List<MoneyTransfer> MoneyTransferPayees { get; set; } = new();
//для реализации связи один ко многим с Картами
[ForeignKey("AccountId")]
public virtual List<Card> Cards { get; set; } = new();
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),
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,
Name = Client.Name,
Patronymic = Client.Patronymic,
AccountNumber = AccountNumber,
Balance = Balance,
PasswordAccount = PasswordAccount,
DateOpen = DateOpen
};
}
2023-04-01 15:33:39 +04:00
}