diff --git a/IceCreamShop/IceCreamShopClientApp/APIClient.cs b/IceCreamShop/IceCreamShopClientApp/APIClient.cs index 11828b7..f07b017 100644 --- a/IceCreamShop/IceCreamShopClientApp/APIClient.cs +++ b/IceCreamShop/IceCreamShopClientApp/APIClient.cs @@ -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(); diff --git a/IceCreamShop/IceCreamShopClientApp/Controllers/HomeController.cs b/IceCreamShop/IceCreamShopClientApp/Controllers/HomeController.cs index cd24646..82089f9 100644 --- a/IceCreamShop/IceCreamShopClientApp/Controllers/HomeController.cs +++ b/IceCreamShop/IceCreamShopClientApp/Controllers/HomeController.cs @@ -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>($"api/client/getmessages?clientId={APIClient.Client.Id}")); } + + [HttpGet] + public Tuple? SwitchPage(bool isNext) + { + if (isNext) + { + APIClient.CurrentPage++; + } + else + { + if (APIClient.CurrentPage == 1) + { + return null; + } + APIClient.CurrentPage--; + } + + 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}" + + "" + (mail.HasRead ? "Прочитано" : "Непрочитано") + "" + + $"{mail.Reply}" + + ""); + } + return Tuple.Create(htmlTable.ToString(), APIClient.CurrentPage.ToString(), APIClient.CurrentPage != 1, true); + } } } \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopClientApp/Views/Home/Mails.cshtml b/IceCreamShop/IceCreamShopClientApp/Views/Home/Mails.cshtml index 54d27b0..5d3c058 100644 --- a/IceCreamShop/IceCreamShopClientApp/Views/Home/Mails.cshtml +++ b/IceCreamShop/IceCreamShopClientApp/Views/Home/Mails.cshtml @@ -1,7 +1,4 @@ -@using IceCreamShopContracts.ViewModels - -@model List - + @{ ViewData["Title"] = "Mails"; } @@ -10,45 +7,75 @@

Заказы

-
- @{ - if (Model == null) - { -

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

- return; - } + + + + + + + + + + + + +
+ Дата письма + + Заголовок + + Текст + + Статус + + Ответ +
+ +
- - - - - - - - - - @foreach (var item in Model) - { - - - - - - } - -
- Дата письма - - Заголовок - - Текст -
- @Html.DisplayFor(modelItem => item.DateDelivery) - - @Html.DisplayFor(modelItem => item.Subject) - - @Html.DisplayFor(modelItem => item.Body) -
- } - \ No newline at end of file + \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopListImplement/Implements/MessageInfoStorage.cs b/IceCreamShop/IceCreamShopListImplement/Implements/MessageInfoStorage.cs index 80b496a..7332916 100644 --- a/IceCreamShop/IceCreamShopListImplement/Implements/MessageInfoStorage.cs +++ b/IceCreamShop/IceCreamShopListImplement/Implements/MessageInfoStorage.cs @@ -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 GetFilteredList(MessageInfoSearchModel model) { - List result = new(); - foreach (var item in _source.Messages) - { - if (item.ClientId.HasValue && item.ClientId == model.ClientId) - { - result.Add(item.GetViewModel); - } - } - return result; - } + List 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 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 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; + } + } } diff --git a/IceCreamShop/IceCreamShopListImplement/Models/MessageInfo.cs b/IceCreamShop/IceCreamShopListImplement/Models/MessageInfo.cs index 240ac3e..e510a2f 100644 --- a/IceCreamShop/IceCreamShopListImplement/Models/MessageInfo.cs +++ b/IceCreamShop/IceCreamShopListImplement/Models/MessageInfo.cs @@ -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, + }; } }