Реализована пагинация сайта через его перезагрузку
This commit is contained in:
parent
fd6e638e70
commit
85bef73aba
@ -10,6 +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 void Connect(IConfiguration configuration)
|
||||
{
|
||||
|
@ -4,6 +4,7 @@ using ConfectioneryContracts.BindingModels;
|
||||
using ConfectioneryContracts.ViewModels;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Diagnostics;
|
||||
using ConfectioneryContracts.SearchModels;
|
||||
|
||||
namespace ConfectioneryClientApp.Controllers
|
||||
{
|
||||
@ -152,7 +153,26 @@ namespace ConfectioneryClientApp.Controllers
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View(APIClient.GetRequest<List<MessageInfoViewModel>>($"api/client/getmessages?clientId={APIClient.Client.Id}"));
|
||||
ViewBag.CurrentPage = APIClient.CurrentPage;
|
||||
return View(APIClient.GetRequest<List<MessageInfoViewModel>>($"api/client/getmessages?clientId={APIClient.Client.Id}&page={APIClient.CurrentPage}"));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public void SwitchPage(bool isNext)
|
||||
{
|
||||
if (isNext)
|
||||
{
|
||||
APIClient.CurrentPage++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (APIClient.CurrentPage == 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
APIClient.CurrentPage--;
|
||||
}
|
||||
Mails();
|
||||
}
|
||||
}
|
||||
}
|
@ -5,50 +5,82 @@
|
||||
@{
|
||||
ViewData["Title"] = "Mails";
|
||||
}
|
||||
<div class="text-center">
|
||||
@{
|
||||
if (Model == null)
|
||||
{
|
||||
<h3 class="display-4">Авторизируйтесь</h3>
|
||||
return;
|
||||
}
|
||||
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
Дата письма
|
||||
</th>
|
||||
<th>
|
||||
Заголовок
|
||||
</th>
|
||||
<th>
|
||||
Текст
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in Model)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.DateDelivery)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Subject)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Body)
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
<ul class="pagination justify-content-center">
|
||||
<li id="prev-page" class="page-item">
|
||||
<a class="page-link" href="#" aria-label="Previous">
|
||||
<span aria-hidden="true">«</span>
|
||||
<span class="sr-only">Предыдущее</span>
|
||||
</a>
|
||||
</li>
|
||||
<li id="current-page" class="page-item"><a class="page-link">
|
||||
@ViewBag.CurrentPage.ToString()
|
||||
</a></li>
|
||||
<li class="page-item">
|
||||
<a id="next-page" class="page-link" href="#" aria-label="Next">
|
||||
<span aria-hidden="true">»</span>
|
||||
<span class="sr-only">Следующее</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
}
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function onClicked(isNext) {
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
url: "/Home/SwitchPage",
|
||||
data: { isNext: isNext },
|
||||
success: function () {
|
||||
location.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
$("#prev-page").on('click', () => onClicked(false));
|
||||
$("#next-page").on('click', () => onClicked(true));
|
||||
|
||||
</script>
|
||||
|
||||
<div class="text-center">
|
||||
<h1 class="display-4">Заказы</h1>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="text-center">
|
||||
@{
|
||||
if (Model == null)
|
||||
{
|
||||
<h3 class="display-4">Авторизируйтесь</h3>
|
||||
return;
|
||||
}
|
||||
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
Дата письма
|
||||
</th>
|
||||
<th>
|
||||
Заголовок
|
||||
</th>
|
||||
<th>
|
||||
Текст
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in Model)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.DateDelivery)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Subject)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Body)
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
</div>
|
||||
</div>
|
@ -14,6 +14,7 @@ namespace ConfectioneryRestApi.Controllers
|
||||
|
||||
private readonly IClientLogic _logic;
|
||||
private readonly IMessageInfoLogic _mailLogic;
|
||||
public int pageSize = 3;
|
||||
|
||||
public ClientController(IClientLogic logic, IMessageInfoLogic mailLogic, ILogger<ClientController> logger)
|
||||
{
|
||||
@ -70,13 +71,15 @@ namespace ConfectioneryRestApi.Controllers
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<MessageInfoViewModel>? GetMessages(int clientId)
|
||||
public List<MessageInfoViewModel>? GetMessages(int clientId, int page)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mailLogic.ReadList(new MessageInfoSearchModel
|
||||
return _mailLogic.ReadList(new()
|
||||
{
|
||||
ClientId = clientId
|
||||
ClientId = clientId,
|
||||
Page = page,
|
||||
PageSize = pageSize
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
Loading…
Reference in New Issue
Block a user