From 22443213651ca13623f074f97e55900d78bbd651 Mon Sep 17 00:00:00 2001 From: shadowik Date: Wed, 17 May 2023 20:04:01 +0400 Subject: [PATCH] ReportCards --- .../Controllers/HomeController.cs | 53 ++++++++++- .../Views/Home/ReportWithCards.cshtml | 94 +++++++++++++------ .../ViewModels/CheckboxViewModel.cs | 17 ++++ ...tingViewModel .cs => DebitingViewModel.cs} | 0 .../ViewModels/ReportCardViewModel.cs | 12 +++ .../ViewModels/ReportClientCardsViewModel.cs | 6 +- .../ViewModels/ReportClientViewModel.cs | 2 +- .../ViewModels/ReportViewModel.cs | 29 ++++++ .../Enums/TypeOperationEnum.cs | 14 +++ 9 files changed, 188 insertions(+), 39 deletions(-) create mode 100644 BankYouBankrupt/BankYouBankruptContracts/ViewModels/CheckboxViewModel.cs rename BankYouBankrupt/BankYouBankruptContracts/ViewModels/{DebitingViewModel .cs => DebitingViewModel.cs} (100%) create mode 100644 BankYouBankrupt/BankYouBankruptContracts/ViewModels/ReportCardViewModel.cs create mode 100644 BankYouBankrupt/BankYouBankruptContracts/ViewModels/ReportViewModel.cs create mode 100644 BankYouBankrupt/BankYouBankruptDataModels/Enums/TypeOperationEnum.cs diff --git a/BankYouBankrupt/BankYouBankruptClientApp/Controllers/HomeController.cs b/BankYouBankrupt/BankYouBankruptClientApp/Controllers/HomeController.cs index a13f342..d2ddd27 100644 --- a/BankYouBankrupt/BankYouBankruptClientApp/Controllers/HomeController.cs +++ b/BankYouBankrupt/BankYouBankruptClientApp/Controllers/HomeController.cs @@ -247,9 +247,56 @@ namespace BankYouBankruptClientApp.Controllers return Redirect("~/Home/Enter"); } - return View(new ReportClientCardsViewModel() { - Cards = APIClient.GetRequest>($"api/Card/GetUsersCardsList?id={APIClient.Client.Id}") - }); + return View(new ReportClientCardsViewModel() + { + Cards = APIClient.GetRequest>($"api/Card/GetUsersCardsList?id={APIClient.Client.Id}").Select(x => new CheckboxViewModel() { + Id = x.Id, + LabelName = x.Number, + IsChecked = false + }).ToList() + }) ; + } + + [HttpPost] + public IActionResult ReportWithCards(List cards) + { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + + List cardList = cards.Where(x => x.IsChecked).Select(x => x.Id).ToList(); + List creditings = APIClient.GetRequest>($"api/Client/getUsersCreditings?userId={APIClient.Client.Id}") + .Where(x => cardList.Contains(x.CardId)).Select(x => new ReportViewModel() { + Id=x.Id, + CardId=x.CardId, + DateOpen=x.DateOpen, + DateClose=x.DateClose, + CardNumber=x.CardNumber, + Status = x.Status, + Sum = x.Sum, + TypeOperation = TypeOperationEnum.Пополнение + }).ToList(); + List debitings = APIClient.GetRequest>($"api/Client/getUsersDebitings?userId={APIClient.Client.Id}") + .Where(x => cardList.Contains(x.CardId)).Select(x => new ReportViewModel() + { + Id = x.Id, + CardId = x.CardId, + DateOpen = x.DateOpen, + DateClose = x.DateClose, + CardNumber = x.CardNumber, + Status = x.Status, + Sum = x.Sum, + TypeOperation = TypeOperationEnum.Снятие + }).ToList(); + List result = creditings.Concat(debitings).OrderBy(x => x.DateOpen).ToList(); + + return View(new ReportClientCardsViewModel() + { + Cards = cards, + Operations = result, + + }) ; } } } \ No newline at end of file diff --git a/BankYouBankrupt/BankYouBankruptClientApp/Views/Home/ReportWithCards.cshtml b/BankYouBankrupt/BankYouBankruptClientApp/Views/Home/ReportWithCards.cshtml index 25d24bc..5be8d19 100644 --- a/BankYouBankrupt/BankYouBankruptClientApp/Views/Home/ReportWithCards.cshtml +++ b/BankYouBankrupt/BankYouBankruptClientApp/Views/Home/ReportWithCards.cshtml @@ -15,41 +15,73 @@
- @foreach (var item in Model.Cards) - { -
- - -
- - } +
+ @for (var item = 0; item < @Model.Cards.Count(); item++) + { +
+ + + + +
+ } +
+ +
+
- - - - - - - - - - - - -
- Номер карты - - Сумма - - Статус - - Дата открытия - - Дата закрытия -
+ + + + + + + + + + + + + @foreach (var item in Model.Operations) + { + + + + + + + + + } + +
+ Номер карты + + Тип операции + + Сумма + + Статус + + Дата открытия + + Дата закрытия +
+ @Html.DisplayFor(modelItem => item.CardNumber) + + @Html.DisplayFor(modelItem => item.TypeOperation) + + @Html.DisplayFor(modelItem => item.Sum) + + @Html.DisplayFor(modelItem => item.Status) + + @Html.DisplayFor(modelItem => item.DateOpen) + + @Html.DisplayFor(modelItem => item.DateClose) +
diff --git a/BankYouBankrupt/BankYouBankruptContracts/ViewModels/CheckboxViewModel.cs b/BankYouBankrupt/BankYouBankruptContracts/ViewModels/CheckboxViewModel.cs new file mode 100644 index 0000000..a336b18 --- /dev/null +++ b/BankYouBankrupt/BankYouBankruptContracts/ViewModels/CheckboxViewModel.cs @@ -0,0 +1,17 @@ +using BankYouBankruptDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BankYouBankruptContracts.ViewModels +{ + public class CheckboxViewModel + { + public int Id { get; set; } + public string LabelName { get; set; } + public bool IsChecked { get; set; } + } +} diff --git a/BankYouBankrupt/BankYouBankruptContracts/ViewModels/DebitingViewModel .cs b/BankYouBankrupt/BankYouBankruptContracts/ViewModels/DebitingViewModel.cs similarity index 100% rename from BankYouBankrupt/BankYouBankruptContracts/ViewModels/DebitingViewModel .cs rename to BankYouBankrupt/BankYouBankruptContracts/ViewModels/DebitingViewModel.cs diff --git a/BankYouBankrupt/BankYouBankruptContracts/ViewModels/ReportCardViewModel.cs b/BankYouBankrupt/BankYouBankruptContracts/ViewModels/ReportCardViewModel.cs new file mode 100644 index 0000000..57ce51b --- /dev/null +++ b/BankYouBankrupt/BankYouBankruptContracts/ViewModels/ReportCardViewModel.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BankYouBankruptContracts.ViewModels +{ + internal class ReportCardViewModel + { + } +} diff --git a/BankYouBankrupt/BankYouBankruptContracts/ViewModels/ReportClientCardsViewModel.cs b/BankYouBankrupt/BankYouBankruptContracts/ViewModels/ReportClientCardsViewModel.cs index 6c2512b..7d92f4d 100644 --- a/BankYouBankrupt/BankYouBankruptContracts/ViewModels/ReportClientCardsViewModel.cs +++ b/BankYouBankrupt/BankYouBankruptContracts/ViewModels/ReportClientCardsViewModel.cs @@ -8,10 +8,8 @@ namespace BankYouBankruptContracts.ViewModels { public class ReportClientCardsViewModel { - public List? Cards { get; set; } = new(); + public List? Cards { get; set; } = new(); - public List? Debitings { get; set; } = new(); - - public List? Creditings { get; set; } = new(); + public List? Operations { get; set; } = new(); } } diff --git a/BankYouBankrupt/BankYouBankruptContracts/ViewModels/ReportClientViewModel.cs b/BankYouBankrupt/BankYouBankruptContracts/ViewModels/ReportClientViewModel.cs index 71bbdab..3084974 100644 --- a/BankYouBankrupt/BankYouBankruptContracts/ViewModels/ReportClientViewModel.cs +++ b/BankYouBankrupt/BankYouBankruptContracts/ViewModels/ReportClientViewModel.cs @@ -14,4 +14,4 @@ namespace BankYouBankruptContracts.ViewModels public DateTime? DateComplite { get; set; } } -} +} \ No newline at end of file diff --git a/BankYouBankrupt/BankYouBankruptContracts/ViewModels/ReportViewModel.cs b/BankYouBankrupt/BankYouBankruptContracts/ViewModels/ReportViewModel.cs new file mode 100644 index 0000000..d1b7a28 --- /dev/null +++ b/BankYouBankrupt/BankYouBankruptContracts/ViewModels/ReportViewModel.cs @@ -0,0 +1,29 @@ +using BankYouBankruptDataModels.Enums; +using BankYouBankruptDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BankYouBankruptContracts.ViewModels +{ + public class ReportViewModel + { + public int Id { get; set; } + + public int CardId { get; set; } + + public string? CardNumber { get; set; } + + public int Sum { get; set; } + + public DateTime DateOpen { get; set; } + + public DateTime? DateClose { get; set; } + + public StatusEnum Status { get; set; } + + public TypeOperationEnum TypeOperation { get; set; } + } +} diff --git a/BankYouBankrupt/BankYouBankruptDataModels/Enums/TypeOperationEnum.cs b/BankYouBankrupt/BankYouBankruptDataModels/Enums/TypeOperationEnum.cs new file mode 100644 index 0000000..1356e76 --- /dev/null +++ b/BankYouBankrupt/BankYouBankruptDataModels/Enums/TypeOperationEnum.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BankYouBankruptDataModels.Enums +{ + public enum TypeOperationEnum + { + Снятие = 1, + Пополнение = 2 + } +}