Реализована пагинация сайта через его перезагрузку
This commit is contained in:
parent
fd6e638e70
commit
85bef73aba
@ -10,6 +10,7 @@ namespace ConfectioneryClientApp
|
|||||||
private static readonly HttpClient _client = new();
|
private static readonly HttpClient _client = new();
|
||||||
|
|
||||||
public static ClientViewModel? Client { get; set; } = null;
|
public static ClientViewModel? Client { get; set; } = null;
|
||||||
|
public static int CurrentPage { get; set; } = 1;
|
||||||
|
|
||||||
public static void Connect(IConfiguration configuration)
|
public static void Connect(IConfiguration configuration)
|
||||||
{
|
{
|
||||||
|
@ -4,6 +4,7 @@ using ConfectioneryContracts.BindingModels;
|
|||||||
using ConfectioneryContracts.ViewModels;
|
using ConfectioneryContracts.ViewModels;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using ConfectioneryContracts.SearchModels;
|
||||||
|
|
||||||
namespace ConfectioneryClientApp.Controllers
|
namespace ConfectioneryClientApp.Controllers
|
||||||
{
|
{
|
||||||
@ -152,7 +153,26 @@ namespace ConfectioneryClientApp.Controllers
|
|||||||
{
|
{
|
||||||
return Redirect("~/Home/Enter");
|
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,12 +5,6 @@
|
|||||||
@{
|
@{
|
||||||
ViewData["Title"] = "Mails";
|
ViewData["Title"] = "Mails";
|
||||||
}
|
}
|
||||||
|
|
||||||
<div class="text-center">
|
|
||||||
<h1 class="display-4">Заказы</h1>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
@{
|
@{
|
||||||
if (Model == null)
|
if (Model == null)
|
||||||
@ -50,5 +44,43 @@
|
|||||||
}
|
}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</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>
|
</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>
|
@ -14,6 +14,7 @@ namespace ConfectioneryRestApi.Controllers
|
|||||||
|
|
||||||
private readonly IClientLogic _logic;
|
private readonly IClientLogic _logic;
|
||||||
private readonly IMessageInfoLogic _mailLogic;
|
private readonly IMessageInfoLogic _mailLogic;
|
||||||
|
public int pageSize = 3;
|
||||||
|
|
||||||
public ClientController(IClientLogic logic, IMessageInfoLogic mailLogic, ILogger<ClientController> logger)
|
public ClientController(IClientLogic logic, IMessageInfoLogic mailLogic, ILogger<ClientController> logger)
|
||||||
{
|
{
|
||||||
@ -70,13 +71,15 @@ namespace ConfectioneryRestApi.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public List<MessageInfoViewModel>? GetMessages(int clientId)
|
public List<MessageInfoViewModel>? GetMessages(int clientId, int page)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return _mailLogic.ReadList(new MessageInfoSearchModel
|
return _mailLogic.ReadList(new()
|
||||||
{
|
{
|
||||||
ClientId = clientId
|
ClientId = clientId,
|
||||||
|
Page = page,
|
||||||
|
PageSize = pageSize
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
Loading…
Reference in New Issue
Block a user