From 5c58ac9317862005ac9bc5a033232a4064ae91ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Sat, 18 Mar 2023 00:02:03 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B2=D0=B5=D0=B4=D0=B5=D0=BD?= =?UTF-8?q?=D0=B0=20=D0=B4=D0=BE=20=D1=83=D0=BC=D0=B0=20=D0=BF=D0=B0=D0=B3?= =?UTF-8?q?=D0=B8=D0=BD=D0=B0=D1=86=D0=B8=D1=8F=20=D0=BD=D0=B0=20=D1=81?= =?UTF-8?q?=D0=B0=D0=B9=D1=82=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ConfectioneryClientApp/APIClient.cs | 2 +- .../Controllers/HomeController.cs | 32 ++++++++-- .../Views/Home/Mails.cshtml | 60 ++++++++----------- 3 files changed, 52 insertions(+), 42 deletions(-) diff --git a/ConfectioneryClientApp/APIClient.cs b/ConfectioneryClientApp/APIClient.cs index 2ca7837..ed25668 100644 --- a/ConfectioneryClientApp/APIClient.cs +++ b/ConfectioneryClientApp/APIClient.cs @@ -10,7 +10,7 @@ namespace ConfectioneryClientApp private static readonly HttpClient _client = new(); public static ClientViewModel? Client { get; set; } = null; - public static int CurrentPage { get; set; } = 1; + public static int CurrentPage { get; set; } = 0; public static void Connect(IConfiguration configuration) { diff --git a/ConfectioneryClientApp/Controllers/HomeController.cs b/ConfectioneryClientApp/Controllers/HomeController.cs index 8e44e22..ab48d93 100644 --- a/ConfectioneryClientApp/Controllers/HomeController.cs +++ b/ConfectioneryClientApp/Controllers/HomeController.cs @@ -4,7 +4,9 @@ using ConfectioneryContracts.BindingModels; using ConfectioneryContracts.ViewModels; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; +using System.Text; using ConfectioneryContracts.SearchModels; +using Microsoft.AspNetCore.Mvc.Rendering; namespace ConfectioneryClientApp.Controllers { @@ -153,12 +155,15 @@ namespace ConfectioneryClientApp.Controllers { return Redirect("~/Home/Enter"); } - ViewBag.CurrentPage = APIClient.CurrentPage; - return View(APIClient.GetRequest>($"api/client/getmessages?clientId={APIClient.Client.Id}&page={APIClient.CurrentPage}")); + return View(); } + /// + /// Switches the page. + /// + /// Возвращает кортеж с таблицой в html, текущей страницей писем, выключать ли кнопку пред. страницы, выключать ли кнопку след. страницы [HttpGet] - public void SwitchPage(bool isNext) + public Tuple? SwitchPage(bool isNext) { if (isNext) { @@ -168,11 +173,28 @@ namespace ConfectioneryClientApp.Controllers { if (APIClient.CurrentPage == 1) { - return; + return null; } APIClient.CurrentPage--; } - Mails(); + + var res = APIClient.GetRequest>($"api/client/getmessages?clientId={APIClient.Client!.Id}&page={APIClient.CurrentPage}"); + if (isNext && (res == null || res.Count == 0)) + { + APIClient.CurrentPage--; + return Tuple.Create(null, null, APIClient.CurrentPage != 1, false); + } + + StringBuilder htmlTable = new(); + foreach (var mail in res) + { + htmlTable.Append("" + + $"{mail.DateDelivery}" + + $"{mail.Subject}" + + $"{mail.Body}" + + ""); + } + return Tuple.Create(htmlTable.ToString(), APIClient.CurrentPage.ToString(), APIClient.CurrentPage != 1, true); } } } \ No newline at end of file diff --git a/ConfectioneryClientApp/Views/Home/Mails.cshtml b/ConfectioneryClientApp/Views/Home/Mails.cshtml index 64df4b7..1926238 100644 --- a/ConfectioneryClientApp/Views/Home/Mails.cshtml +++ b/ConfectioneryClientApp/Views/Home/Mails.cshtml @@ -1,19 +1,8 @@ -@using ConfectioneryContracts.ViewModels - -@model List - -@{ +@{ ViewData["Title"] = "Mails"; }
- @{ - if (Model == null) - { -

Авторизируйтесь

- return; - } - - +
- - @foreach (var item in Model) - { - - - - - - } +
@@ -27,21 +16,7 @@
- @Html.DisplayFor(modelItem => item.DateDelivery) - - @Html.DisplayFor(modelItem => item.Subject) - - @Html.DisplayFor(modelItem => item.Body) -
- }