может работает, а может и нет, а может не может
This commit is contained in:
parent
4cf40944f5
commit
7fae4ed8f3
@ -11,7 +11,9 @@ namespace IceCreamShopClientApp
|
||||
|
||||
public static ClientViewModel? Client { get; set; } = null;
|
||||
|
||||
public static void Connect(IConfiguration configuration)
|
||||
public static int CurrentPage { get; set; } = 0;
|
||||
|
||||
public static void Connect(IConfiguration configuration)
|
||||
{
|
||||
_client.BaseAddress = new Uri(configuration["IPAddress"]);
|
||||
_client.DefaultRequestHeaders.Accept.Clear();
|
||||
|
@ -3,6 +3,7 @@ using IceCreamShopContracts.ViewModels;
|
||||
using IceCreamShopClientApp.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
|
||||
namespace IceCreamShopClientApp.Controllers
|
||||
{
|
||||
@ -153,5 +154,42 @@ namespace IceCreamShopClientApp.Controllers
|
||||
}
|
||||
return View(APIClient.GetRequest<List<MessageInfoViewModel>>($"api/client/getmessages?clientId={APIClient.Client.Id}"));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public Tuple<string?, string?, bool, bool>? SwitchPage(bool isNext)
|
||||
{
|
||||
if (isNext)
|
||||
{
|
||||
APIClient.CurrentPage++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (APIClient.CurrentPage == 1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
APIClient.CurrentPage--;
|
||||
}
|
||||
|
||||
var res = APIClient.GetRequest<List<MessageInfoViewModel>>($"api/client/getmessages?clientId={APIClient.Client!.Id}&page={APIClient.CurrentPage}");
|
||||
if (isNext && (res == null || res.Count == 0))
|
||||
{
|
||||
APIClient.CurrentPage--;
|
||||
return Tuple.Create<string?, string?, bool, bool>(null, null, APIClient.CurrentPage != 1, false);
|
||||
}
|
||||
|
||||
StringBuilder htmlTable = new();
|
||||
foreach (var mail in res)
|
||||
{
|
||||
htmlTable.Append("<tr>" +
|
||||
$"<td>{mail.DateDelivery}</td>" +
|
||||
$"<td>{mail.Subject}</td>" +
|
||||
$"<td>{mail.Body}</td>" +
|
||||
"<td>" + (mail.HasRead ? "Прочитано" : "Непрочитано") + "</td>" +
|
||||
$"<td>{mail.Reply}</td>" +
|
||||
"</tr>");
|
||||
}
|
||||
return Tuple.Create<string?, string?, bool, bool>(htmlTable.ToString(), APIClient.CurrentPage.ToString(), APIClient.CurrentPage != 1, true);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,4 @@
|
||||
@using IceCreamShopContracts.ViewModels
|
||||
|
||||
@model List<MessageInfoViewModel>
|
||||
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Mails";
|
||||
}
|
||||
@ -10,45 +7,75 @@
|
||||
<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>
|
||||
<th>
|
||||
Статус
|
||||
</th>
|
||||
<th>
|
||||
Ответ
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="mails-table-body">
|
||||
</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 class="page-item">
|
||||
<a id="current-page" class="page-link"></a>
|
||||
</li>
|
||||
<li id="next-page" class="page-item">
|
||||
<a class="page-link" href="#" aria-label="Next">
|
||||
<span aria-hidden="true">»</span>
|
||||
<span class="sr-only">Следующее</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<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>
|
||||
<script>
|
||||
function onClicked(isNext) {
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
url: "/Home/SwitchPage",
|
||||
data: { isNext: isNext },
|
||||
success: function (result) {
|
||||
if (result != null) {
|
||||
if (result.item1 != null && result.item2 != null) {
|
||||
$("#mails-table-body").html(result.item1);
|
||||
$("#current-page").text(result.item2);
|
||||
}
|
||||
if (result.item3)
|
||||
$("#prev-page").removeClass("page-item disabled");
|
||||
else
|
||||
$("#prev-page").addClass("page-item disabled");
|
||||
if (result.item4)
|
||||
$("#next-page").removeClass("page-item disabled");
|
||||
else
|
||||
$("#next-page").addClass("page-item disabled");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
onClicked(true);
|
||||
$("#prev-page").on('click', () => onClicked(false));
|
||||
$("#next-page").on('click', () => onClicked(true));
|
||||
|
||||
</script>
|
@ -6,7 +6,7 @@ using IceCreamShopListImplement.Models;
|
||||
|
||||
namespace IceCreamShopListImplement.Implements
|
||||
{
|
||||
public class MessageInfoStorage
|
||||
public class MessageInfoStorage : IMessageInfoStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
public MessageInfoStorage()
|
||||
@ -26,16 +26,30 @@ namespace IceCreamShopListImplement.Implements
|
||||
|
||||
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
|
||||
{
|
||||
List<MessageInfoViewModel> result = new();
|
||||
foreach (var item in _source.Messages)
|
||||
{
|
||||
if (item.ClientId.HasValue && item.ClientId == model.ClientId)
|
||||
{
|
||||
result.Add(item.GetViewModel);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
List<MessageInfoViewModel> result = new();
|
||||
foreach (var item in _source.Messages)
|
||||
{
|
||||
if (item.ClientId.HasValue && item.ClientId == model.ClientId)
|
||||
{
|
||||
result.Add(item.GetViewModel);
|
||||
}
|
||||
}
|
||||
|
||||
if (!(model.Page.HasValue && model.PageSize.HasValue))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
if (model.Page * model.PageSize >= result.Count)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
List<MessageInfoViewModel> filteredResult = new();
|
||||
for (var i = (model.Page.Value - 1) * model.PageSize.Value; i < model.Page.Value * model.PageSize.Value; i++)
|
||||
{
|
||||
filteredResult.Add(result[i]);
|
||||
}
|
||||
return filteredResult;
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> GetFullList()
|
||||
{
|
||||
@ -57,5 +71,18 @@ namespace IceCreamShopListImplement.Implements
|
||||
_source.Messages.Add(newMessage);
|
||||
return newMessage.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
public MessageInfoViewModel? Update(MessageInfoBindingModel model)
|
||||
{
|
||||
foreach (var message in _source.Messages)
|
||||
{
|
||||
if (message.MessageId.Equals(model.MessageId))
|
||||
{
|
||||
message.Update(model);
|
||||
return message.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,11 @@ namespace IceCreamShopListImplement.Models
|
||||
|
||||
public string Body { get; private set; } = string.Empty;
|
||||
|
||||
public static MessageInfo? Create(MessageInfoBindingModel model)
|
||||
public bool HasRead { get; private set; }
|
||||
|
||||
public string? Reply { get; private set; }
|
||||
|
||||
public static MessageInfo? Create(MessageInfoBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
@ -26,24 +30,37 @@ namespace IceCreamShopListImplement.Models
|
||||
}
|
||||
return new()
|
||||
{
|
||||
Body = model.Body,
|
||||
Subject = model.Subject,
|
||||
ClientId = model.ClientId,
|
||||
MessageId = model.MessageId,
|
||||
SenderName = model.SenderName,
|
||||
DateDelivery = model.DateDelivery,
|
||||
};
|
||||
Body = model.Body,
|
||||
Reply = model.Reply,
|
||||
HasRead = model.HasRead,
|
||||
Subject = model.Subject,
|
||||
ClientId = model.ClientId,
|
||||
MessageId = model.MessageId,
|
||||
SenderName = model.SenderName,
|
||||
DateDelivery = model.DateDelivery,
|
||||
};
|
||||
}
|
||||
|
||||
public MessageInfoViewModel GetViewModel => new()
|
||||
{
|
||||
Body = Body,
|
||||
Subject = Subject,
|
||||
ClientId = ClientId,
|
||||
MessageId = MessageId,
|
||||
SenderName = SenderName,
|
||||
DateDelivery = DateDelivery,
|
||||
};
|
||||
public void Update(MessageInfoBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Reply = model.Reply;
|
||||
HasRead = model.HasRead;
|
||||
}
|
||||
|
||||
public MessageInfoViewModel GetViewModel => new()
|
||||
{
|
||||
Body = Body,
|
||||
Reply = Reply,
|
||||
HasRead = HasRead,
|
||||
Subject = Subject,
|
||||
ClientId = ClientId,
|
||||
MessageId = MessageId,
|
||||
SenderName = SenderName,
|
||||
DateDelivery = DateDelivery,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user