From ecb93145b72af154a591f4b2856d27418c576c8c Mon Sep 17 00:00:00 2001 From: Artyom_Yashin Date: Thu, 2 May 2024 18:40:07 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A7=D0=B5=D0=BB=D0=BE=D0=B2=D0=B5=D1=87?= =?UTF-8?q?=D0=B5=D1=81=D0=BA=D0=B8=D0=B5=20=D0=B2=D1=8B=D0=B1=D0=BE=D1=80?= =?UTF-8?q?=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Views/Home/RequestDelete.cshtml | 4 +- .../SearchModels/CardSearchModel.cs | 5 ++- .../SearchModels/TransferSearchModel.cs | 1 - .../ReportOperationsRequestsViewModel.cs | 16 +++++++ .../ViewModels/ReportTransfersViewModel.cs | 14 +++++++ .../Implements/CardStorage.cs | 42 +++++++++++++++++++ .../Implements/RequestStorage.cs | 3 +- .../Implements/TransferStorage.cs | 3 +- .../BankDatabaseImplement/Models/Operation.cs | 5 ++- 9 files changed, 83 insertions(+), 10 deletions(-) create mode 100644 Bank/BankContracts/ViewModels/ReportOperationsRequestsViewModel.cs create mode 100644 Bank/BankContracts/ViewModels/ReportTransfersViewModel.cs diff --git a/Bank/BankClientApp/Views/Home/RequestDelete.cshtml b/Bank/BankClientApp/Views/Home/RequestDelete.cshtml index 611cb70..66ab581 100644 --- a/Bank/BankClientApp/Views/Home/RequestDelete.cshtml +++ b/Bank/BankClientApp/Views/Home/RequestDelete.cshtml @@ -2,11 +2,11 @@ ViewData["Title"] = "RequestDelete"; }
-

Удаление запрос

+

Удаление заявки

-
Запрос:
+
Заявка:
diff --git a/Bank/BankContracts/SearchModels/CardSearchModel.cs b/Bank/BankContracts/SearchModels/CardSearchModel.cs index 00c86d1..4e736db 100644 --- a/Bank/BankContracts/SearchModels/CardSearchModel.cs +++ b/Bank/BankContracts/SearchModels/CardSearchModel.cs @@ -11,7 +11,8 @@ namespace BankContracts.SearchModels public int? Id { get; set; } public string? Number { get; set; } public int? ClientId { get; set; } - public DateTime? ReleaseDate { get; set; } - public DateTime? ExpirationDate { get; set; } + public DateTime? DateFrom { get; set; } + public DateTime? DateTo { get; set; } + public List? SelectedCardIds { get; set; } } } diff --git a/Bank/BankContracts/SearchModels/TransferSearchModel.cs b/Bank/BankContracts/SearchModels/TransferSearchModel.cs index 31c6e8f..5816e4a 100644 --- a/Bank/BankContracts/SearchModels/TransferSearchModel.cs +++ b/Bank/BankContracts/SearchModels/TransferSearchModel.cs @@ -14,6 +14,5 @@ namespace BankContracts.SearchModels public int? OperationId { get; set; } public int? SenderAccountId { get; set; } public int? RecipientAccountId { get; set; } - public int? CardId { get; set; } } } diff --git a/Bank/BankContracts/ViewModels/ReportOperationsRequestsViewModel.cs b/Bank/BankContracts/ViewModels/ReportOperationsRequestsViewModel.cs new file mode 100644 index 0000000..7f7e923 --- /dev/null +++ b/Bank/BankContracts/ViewModels/ReportOperationsRequestsViewModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BankContracts.ViewModels +{ + public class ReportOperationsRequestsViewModel + { + public string CardNumber { get; set; } = string.Empty; + public List SenderOperations { get; set; } = new(); + public List RecipientOperations { get; set; } = new(); + public List Requests { get; set; } = new(); + } +} diff --git a/Bank/BankContracts/ViewModels/ReportTransfersViewModel.cs b/Bank/BankContracts/ViewModels/ReportTransfersViewModel.cs new file mode 100644 index 0000000..06c3d99 --- /dev/null +++ b/Bank/BankContracts/ViewModels/ReportTransfersViewModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BankContracts.ViewModels +{ + public class ReportTransfersViewModel + { + public string CardNumber { get; set; } = string.Empty; + public List Transfers { get; set; } = new(); + } +} diff --git a/Bank/BankDatabaseImplement/Implements/CardStorage.cs b/Bank/BankDatabaseImplement/Implements/CardStorage.cs index aa925ae..f02b5d6 100644 --- a/Bank/BankDatabaseImplement/Implements/CardStorage.cs +++ b/Bank/BankDatabaseImplement/Implements/CardStorage.cs @@ -29,6 +29,48 @@ namespace BankDatabaseImplement.Implements .Select(x => x.GetViewModel) .ToList(); } + + public List GetReportTransfersList(CardSearchModel model) + { + using var context = new BankDatabase(); + return context.Cards + .Where(c => model.SelectedCardIds == null || model.SelectedCardIds.Contains(c.Id)) + .Include(c => c.RecipientOperations).ThenInclude(x => x.Transfer) + .Include(c => c.SenderOperations).ThenInclude(x => x.Transfer) + .Select(t => new ReportTransfersViewModel() + { + CardNumber = t.Number, + Transfers = context.Transfers + .Include(c => c.Operation) + .Where(x => x.Operation == null || x.Operation.SenderCardId == model.Id || x.Operation.RecipientCardId == model.Id) + .Select(t => t.GetViewModel) + .ToList() + }).ToList(); + } + + public List GetReportOperationsREquestsList(CardSearchModel model) + { + using var context = new BankDatabase(); + return context.Cards + .Select(c => new ReportOperationsRequestsViewModel() + { + CardNumber = c.Number, + SenderOperations = context.Operations + .Where(x => x.OperationTime >= model.DateFrom && x.OperationTime <= model.DateTo && x.SenderCardId == model.Id) + .Select(t => t.GetViewModel) + .ToList(), + RecipientOperations = context.Operations + .Where(x => x.OperationTime >= model.DateFrom && x.OperationTime <= model.DateTo && x.RecipientCardId == model.Id) + .Select(t => t.GetViewModel) + .ToList(), + Requests = context.Requests + .Include(x => x.CardRequests) + .Where(x => x.Cards.Select(x => x.CardId).ToList().Contains(c.Id) && x.RequestTime >= model.DateFrom && x.RequestTime <= model.DateTo) + .Select(r => r.GetViewModel) + .ToList(), + }).ToList(); + } + public CardViewModel? GetElement(CardSearchModel model) { using var context = new BankDatabase(); diff --git a/Bank/BankDatabaseImplement/Implements/RequestStorage.cs b/Bank/BankDatabaseImplement/Implements/RequestStorage.cs index a729b39..e03abf0 100644 --- a/Bank/BankDatabaseImplement/Implements/RequestStorage.cs +++ b/Bank/BankDatabaseImplement/Implements/RequestStorage.cs @@ -31,8 +31,7 @@ namespace BankDatabaseImplement.Implements return context.Requests.Include(x => x.Cards).ThenInclude(x => x.Card) .Where(x => (model.Id.HasValue && x.Id == model.Id) && (!model.DateFrom.HasValue || x.RequestTime >= model.DateFrom) && - (!model.DateTo.HasValue || x.RequestTime <= model.DateTo) && - (!model.CardId.HasValue || x.Cards.Select(x => x.CardId).ToList().Contains(model.CardId.Value)) + (!model.DateTo.HasValue || x.RequestTime <= model.DateTo) ).ToList() .Select(x => x.GetViewModel).ToList(); } diff --git a/Bank/BankDatabaseImplement/Implements/TransferStorage.cs b/Bank/BankDatabaseImplement/Implements/TransferStorage.cs index f4fcd33..5e3e8bb 100644 --- a/Bank/BankDatabaseImplement/Implements/TransferStorage.cs +++ b/Bank/BankDatabaseImplement/Implements/TransferStorage.cs @@ -37,8 +37,7 @@ namespace BankDatabaseImplement.Implements (!model.RecipientAccountId.HasValue || x.RecipientAccountId == model.RecipientAccountId) && (!model.OperationId.HasValue || x.OperationId == model.OperationId) && (!model.DateFrom.HasValue || x.TransferTime >= model.DateFrom) && - (!model.DateTo.HasValue || x.TransferTime <= model.DateTo) && - (!model.CardId.HasValue || x.Operation.RecipientCardId == model.CardId || x.Operation.SenderCardId == model.CardId) + (!model.DateTo.HasValue || x.TransferTime <= model.DateTo) ).Select(x => x.GetViewModel).ToList(); } diff --git a/Bank/BankDatabaseImplement/Models/Operation.cs b/Bank/BankDatabaseImplement/Models/Operation.cs index fb70907..d600523 100644 --- a/Bank/BankDatabaseImplement/Models/Operation.cs +++ b/Bank/BankDatabaseImplement/Models/Operation.cs @@ -5,6 +5,7 @@ using BankDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -23,7 +24,9 @@ namespace BankDatabaseImplement.Models public virtual Card? SenderCard { get; private set; } [Required] public int RecipientCardId { get; set; } - public virtual Card? RecipientCard { get; private set; } + public virtual Card? RecipientCard { get; private set; } + [ForeignKey("OperationId")] + public virtual Transfer? Transfer { get; private set; } public static Operation? Create(OperationBindingModel model) {