From de25c5ce8396ecb2bc059fe958e2988719199a7e Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Sun, 14 May 2023 18:27:41 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BD=D0=BE=D0=B2=D0=B0=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/DebitingStorage.cs | 8 ++++++-- .../BankYouBankruptDatabaseImplement/Models/Account.cs | 3 ++- .../BankYouBankruptDatabaseImplement/Models/Card.cs | 10 ++++++---- .../Models/Crediting.cs | 2 +- .../Models/Debiting.cs | 5 ++--- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/BankYouBankrupt/BankYouBankruptDatabaseImplement/Implements/DebitingStorage.cs b/BankYouBankrupt/BankYouBankruptDatabaseImplement/Implements/DebitingStorage.cs index 6a812fd..aeebce6 100644 --- a/BankYouBankrupt/BankYouBankruptDatabaseImplement/Implements/DebitingStorage.cs +++ b/BankYouBankrupt/BankYouBankruptDatabaseImplement/Implements/DebitingStorage.cs @@ -21,6 +21,7 @@ namespace BankYouBankruptDatabaseImplement.Implements using var context = new BankYouBancruptDatabase(); return context.Debitings + .Include(x => x.Card) .Select(x => x.GetViewModel) .ToList(); } @@ -38,13 +39,15 @@ namespace BankYouBankruptDatabaseImplement.Implements if(model.Status != StatusEnum.Закрыта) { return context.Debitings + .Include(x => x.Card) .Where(x => x.Status == StatusEnum.Открыта) .Select(x => x.GetViewModel) .ToList(); } return context.Debitings - .Where(x => x.CardId == model.CardId) + .Include(x => x.Card) + .Where(x => x.CardId == model.CardId) .Select(x => x.GetViewModel) .ToList(); } @@ -59,7 +62,8 @@ namespace BankYouBankruptDatabaseImplement.Implements using var context = new BankYouBancruptDatabase(); return context.Debitings - .FirstOrDefault(x => (!(model.CardId < 0) && x.CardId == model.CardId) || + .Include(x => x.Card) + .FirstOrDefault(x => (!(model.CardId < 0) && x.CardId == model.CardId) || (model.Id.HasValue && x.Id == model.Id)) ?.GetViewModel; } diff --git a/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Account.cs b/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Account.cs index d3f5fc6..e8fa729 100644 --- a/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Account.cs +++ b/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Account.cs @@ -26,7 +26,7 @@ namespace BankYouBankruptDatabaseImplement.Models public int ClientId { get; set; } //для передачи ФИО клиента - public virtual Client Client { get; set; } = new(); + public virtual Client Client { get; set; } [Required] public string PasswordAccount { get; set; } = string.Empty; @@ -58,6 +58,7 @@ 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, diff --git a/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Card.cs b/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Card.cs index abf03f8..5b14847 100644 --- a/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Card.cs +++ b/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Card.cs @@ -1,6 +1,7 @@ using BankYouBankruptContracts.BindingModels; using BankYouBankruptContracts.ViewModels; using BankYouBankruptDataModels.Models; +using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; @@ -18,18 +19,18 @@ 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; } [Required] - public string Number { get; set; } = String.Empty; + public string Number { get; set; } = string.Empty; [Required] - public string CVC { get; set; } + public string CVC { get; set; } = string.Empty; - [Required] + [Required] public DateTime Period { get; set; } = DateTime.Now; [ForeignKey("CardId")] @@ -56,6 +57,7 @@ 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 diff --git a/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Crediting.cs b/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Crediting.cs index 89b4858..29cff81 100644 --- a/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Crediting.cs +++ b/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Crediting.cs @@ -18,7 +18,7 @@ namespace BankYouBankruptDatabaseImplement.Models [Required] public int CardId { get; set; } - public virtual Card Card { get; set; } = new(); + public virtual Card Card { get; set; } [Required] public int Sum { get; set; } diff --git a/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Debiting.cs b/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Debiting.cs index 3ee94d7..6cfc047 100644 --- a/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Debiting.cs +++ b/BankYouBankrupt/BankYouBankruptDatabaseImplement/Models/Debiting.cs @@ -18,7 +18,7 @@ namespace BankYouBankruptDatabaseImplement.Models [Required] public int CardId { get; set; } - public virtual Card Card { get; set; } = new(); + public virtual Card Card { get; set; } [Required] public int Sum { get; set; } @@ -49,10 +49,9 @@ namespace BankYouBankruptDatabaseImplement.Models { Id = model.Id, CardId = model.CardId, - Card = context.Cards.First(x => x.Id == model.CardId), Sum = model.Sum, DateOpen = model.DateOpen, - Status = model.Status + Status = StatusEnum.Открыта }; }