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) -
- }