From 6e7c9c27f0b5ada37497c1b941271a5a157c15a7 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Sat, 1 Apr 2023 20:27:26 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20Models=20=D0=B2=20DatabaseImplements=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=BA=D0=B0=D1=81=D1=81=D0=B8=D1=80=D0=B0?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Models/Account.cs | 71 ++++++++++++++++--- .../Models/CashWithdrawal.cs | 38 ++++++++-- .../Models/Cashier.cs | 69 +++++++++++++++--- .../Models/MoneyTransfer.cs | 43 +++++++++-- 4 files changed, 190 insertions(+), 31 deletions(-) diff --git a/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Account.cs b/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Account.cs index 34b70cf..d87bea9 100644 --- a/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Account.cs +++ b/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Account.cs @@ -1,6 +1,11 @@ -using BankYouBankruptDataModels.Models; +using BankYouBankruptContracts.BindingModels; +using BankYouBankruptContracts.ViewModels; +using BankYouBankruptDataModels.Models; using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -9,18 +14,66 @@ namespace BankYouBankruptDatabaseImplement.Models { public class Account : IAccountModel { - public string AccountNumber => throw new NotImplementedException(); + public int Id { get; set; } - public int CashierId => throw new NotImplementedException(); + [Required] + public string AccountNumber { get; set; } = string.Empty; - public int ClientId => throw new NotImplementedException(); + [Required] + public int CashierId { get; set; } - public string PasswordAccount => throw new NotImplementedException(); + [Required] + public int ClientId { get; set; } - public double Balance => throw new NotImplementedException(); + [Required] + public string PasswordAccount { get; set; } = string.Empty; - public DateTime DateOpen => throw new NotImplementedException(); + [Required] + public double Balance { get; set; } - public int Id => throw new NotImplementedException(); - } + [Required] + public DateTime DateOpen { get; set; } = DateTime.Now; + + //для реализации связи один ко многим со Снятием наличных + [ForeignKey("AccountId")] + public virtual List CashWithdrawals { get; set; } = new(); + + //для реализации связи один ко многим с Переводом денег + [ForeignKey("AccountSenderId")] + public virtual List MoneyTransferSenders { get; set; } = new(); + + [ForeignKey("AccountPayeeId")] + public virtual List MoneyTransferPayees { get; set; } = new(); + + public static Account Create(BankYouBancruptDatabase context, AccountBindingModel model) + { + return new Account() + { + Id = model.Id, + ClientId = 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; + PasswordAccount = model.PasswordAccount; + } + + public AccountViewModel GetViewModel => new() + { + Id = Id, + CashierId = CashierId, + ClientId = ClientId, + AccountNumber = AccountNumber, + Balance = Balance, + PasswordAccount = PasswordAccount, + DateOpen = DateOpen + }; + } } diff --git a/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/CashWithdrawal.cs b/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/CashWithdrawal.cs index ff555a8..ca27379 100644 --- a/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/CashWithdrawal.cs +++ b/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/CashWithdrawal.cs @@ -1,6 +1,10 @@ -using BankYouBankruptDataModels.Models; +using BankYouBankruptContracts.BindingModels; +using BankYouBankruptContracts.ViewModels; +using BankYouBankruptDataModels.Models; using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -9,12 +13,34 @@ namespace BankYouBankruptDatabaseImplement.Models { public class CashWithdrawal : ICashWithdrawalModel { - public int AccountId => throw new NotImplementedException(); + public int Id { get; set; } - public int Sum => throw new NotImplementedException(); + [Required] + public int AccountId { get; set; } - public DateTime DateOperation => throw new NotImplementedException(); + [Required] + public int Sum { get; set; } - public int Id => throw new NotImplementedException(); - } + [Required] + public DateTime DateOperation { get; set; } + + public static CashWithdrawal Create(BankYouBancruptDatabase context, CashWithdrawalBindingModel model) + { + return new CashWithdrawal() + { + Id = model.Id, + AccountId = model.AccountId, + Sum = model.Sum, + DateOperation = model.DateOperation + }; + } + + public CashWithdrawalViewModel GetViewModel => new() + { + Id = Id, + AccountId = AccountId, + Sum = Sum, + DateOperation = DateOperation + }; + } } diff --git a/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Cashier.cs b/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Cashier.cs index 777c2a6..5332560 100644 --- a/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Cashier.cs +++ b/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Cashier.cs @@ -1,6 +1,11 @@ -using BankYouBankruptDataModels.Models; +using BankYouBankruptContracts.BindingModels; +using BankYouBankruptContracts.ViewModels; +using BankYouBankruptDataModels.Models; using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -9,18 +14,64 @@ namespace BankYouBankruptDatabaseImplement.Models { public class Cashier : ICashierModel { - public string Password => throw new NotImplementedException(); + public int Id { get; set; } - public string Name => throw new NotImplementedException(); + [Required] + public string Password { get; set; } = string.Empty; - public string Surname => throw new NotImplementedException(); + [Required] + public string Name { get; set; } = string.Empty; - public string Patronymic => throw new NotImplementedException(); + [Required] + public string Surname { get; set; } = string.Empty; - public string Email => throw new NotImplementedException(); + [Required] + public string Patronymic { get; set; } = string.Empty; - public string Telephone => throw new NotImplementedException(); + [Required] + public string Email { get; set; } = string.Empty; - public int Id => throw new NotImplementedException(); - } + [Required] + public string Telephone { get; set; } = string.Empty; + + //для реализации связи один ко многим со Счётом + [ForeignKey("CashierId")] + public virtual List Accounts { get; set; } = new(); + + public static Cashier Create(BankYouBancruptDatabase context, CashierBindingModel model) + { + return new Cashier() + { + Id = model.Id, + Name = model.Name, + Surname = model.Surname, + Patronymic = model.Patronymic, + Email = model.Email, + Telephone = model.Telephone, + Password = model.Password + }; + } + + public void Update(CashierBindingModel model) + { + Id = model.Id; + Name = model.Name; + Surname = model.Surname; + Patronymic = model.Patronymic; + Email = model.Email; + Telephone = model.Telephone; + Password = model.Password; + } + + public CashierViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + Surname = Surname, + Patronymic = Patronymic, + Email = Email, + Telephone = Telephone, + Password = Password + }; + } } diff --git a/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/MoneyTransfer.cs b/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/MoneyTransfer.cs index d852fe6..c7aec11 100644 --- a/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/MoneyTransfer.cs +++ b/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/MoneyTransfer.cs @@ -1,6 +1,10 @@ -using BankYouBankruptDataModels.Models; +using BankYouBankruptContracts.BindingModels; +using BankYouBankruptContracts.ViewModels; +using BankYouBankruptDataModels.Models; using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -9,14 +13,39 @@ namespace BankYouBankruptDatabaseImplement.Models { public class MoneyTransfer : IMoneyTransferModel { - public int Sum => throw new NotImplementedException(); + public int Id { get; set; } - public int AccountSenderId => throw new NotImplementedException(); + [Required] + public int Sum { get; set; } - public int AccountPayeeId => throw new NotImplementedException(); + [Required] + public int AccountSenderId { get; set; } - public DateTime DateOperation => throw new NotImplementedException(); + [Required] + public int AccountPayeeId { get; set; } - public int Id => throw new NotImplementedException(); - } + [Required] + public DateTime DateOperation { get; set; } + + public static MoneyTransfer Create(BankYouBancruptDatabase context, MoneyTransferBindingModel model) + { + return new MoneyTransfer() + { + Id = model.Id, + Sum = model.Sum, + AccountSenderId = model.AccountSenderId, + AccountPayeeId = model.AccountPayeeId, + DateOperation = model.DateOperation + }; + } + + public MoneyTransferViewModel GetViewModel => new() + { + Id = Id, + AccountPayeeId = AccountPayeeId, + AccountSenderId = AccountSenderId, + DateOperation = DateOperation, + Sum = Sum + }; + } }