diff --git a/BankYouBankrupt/BankYouBankruptDatabaseImplement/Implements/AccountStorage.cs b/BankYouBankrupt/BankYouBankruptDatabaseImplement/Implements/AccountStorage.cs index 68866bd..d97227a 100644 --- a/BankYouBankrupt/BankYouBankruptDatabaseImplement/Implements/AccountStorage.cs +++ b/BankYouBankrupt/BankYouBankruptDatabaseImplement/Implements/AccountStorage.cs @@ -25,17 +25,39 @@ namespace BankYouBankruptDatabaseImplement.Implements public List GetFilteredList(AccountSearchModel model) { - if (string.IsNullOrEmpty(model.AccountNumber)) - { - return new(); - } - using var context = new BankYouBancruptDatabase(); - return context.Accounts + if (!string.IsNullOrEmpty(model.AccountNumber)) + { + return context.Accounts + .Include(x => x.Client) .Where(x => x.AccountNumber.Contains(model.AccountNumber)) .Select(x => x.GetViewModel) .ToList(); + } + + if (model.CashierId.HasValue) + { + return context.Accounts + .Include(x => x.Client) + .Where(x => x.CashierId == model.CashierId) + .Select(x => x.GetViewModel) + .ToList(); + } + + if (model.ClientId.HasValue) + { + return context.Accounts + .Include(x => x.Client) + .Where(x => x.ClientId == model.ClientId) + .Select(x => x.GetViewModel) + .ToList(); + } + + return context.Accounts + .Include(x => x.Client) + .Select(x => x.GetViewModel) + .ToList(); } public AccountViewModel? GetElement(AccountSearchModel model) diff --git a/BankYouBankrupt/BankYouBankruptDatabaseImplement/Implements/CardStorage.cs b/BankYouBankrupt/BankYouBankruptDatabaseImplement/Implements/CardStorage.cs index 99503b1..dd92aab 100644 --- a/BankYouBankrupt/BankYouBankruptDatabaseImplement/Implements/CardStorage.cs +++ b/BankYouBankrupt/BankYouBankruptDatabaseImplement/Implements/CardStorage.cs @@ -3,6 +3,7 @@ using BankYouBankruptContracts.SearchModels; using BankYouBankruptContracts.StoragesContracts; using BankYouBankruptContracts.ViewModels; using BankYouBankruptDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; @@ -43,16 +44,29 @@ namespace BankYouBankruptDatabaseImplement.Implements public List GetFilteredList(CardSearchModel model) { - if (string.IsNullOrEmpty(model.Number)) - { - return new(); - } - using var context = new BankYouBancruptDatabase(); - return context.Cards - .Where(x => x.Number.Contains(model.Number)) - .Select(x => x.GetViewModel) + if (!string.IsNullOrEmpty(model.Number)) + { + return context.Cards + .Include(x => x.Client) + .Where(x => x.Number.Contains(model.Number)) + .Select(x => x.GetViewModel) + .ToList(); + } + + if (model.ClientID.HasValue) + { + return context.Cards + .Include(x => x.Client) + .Where(x => x.ClientID == model.ClientID) + .Select(x => x.GetViewModel) + .ToList(); + } + + return context.Cards + .Include(x => x.Client) + .Select(x => x.GetViewModel) .ToList(); } diff --git a/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Account.cs b/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Account.cs index 0015564..5295db0 100644 --- a/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Account.cs +++ b/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Account.cs @@ -58,7 +58,6 @@ namespace BankYouBankruptDatabaseImplement.Models { Id = model.Id, ClientId = model.ClientId, - Client = context.Clients.First(x => x.Id == model.ClientId), PasswordAccount = model.PasswordAccount, Balance = model.Balance, DateOpen = model.DateOpen, @@ -78,6 +77,8 @@ namespace BankYouBankruptDatabaseImplement.Models Id = Id, CashierId = CashierId, ClientId = ClientId, + Name = Client.Name, + Patronymic = Client.Patronymic, AccountNumber = AccountNumber, Balance = Balance, PasswordAccount = PasswordAccount, diff --git a/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Card.cs b/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Card.cs index b7790d5..66ce30a 100644 --- a/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Card.cs +++ b/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Card.cs @@ -18,7 +18,7 @@ namespace BankYouBankruptDatabaseImplement.Models [Required] public int ClientID { get; set; } - public virtual Client Client { get; set; } = new(); + public virtual Client Client { get; set; } [Required] public int AccountId { get; set; } @@ -56,7 +56,6 @@ namespace BankYouBankruptDatabaseImplement.Models Id = model.Id, AccountId = model.AccountId, ClientID = model.ClientID, - Client = context.Clients.First(x => x.Id == model.ClientID), Number = model.Number, Period = model.Period, CVC = model.CVC