diff --git a/SushiBar/SushiBarClientApi/Controllers/HomeController.cs b/SushiBar/SushiBarClientApi/Controllers/HomeController.cs index c4bf1df..82a75fa 100644 --- a/SushiBar/SushiBarClientApi/Controllers/HomeController.cs +++ b/SushiBar/SushiBarClientApi/Controllers/HomeController.cs @@ -22,6 +22,7 @@ namespace SushiBarClientApp.Controllers return View(APIClient.GetRequest>($"api/main/getorders?clientId={APIClient.Client.Id}")); } + [HttpGet] public IActionResult Privacy() { @@ -31,6 +32,7 @@ namespace SushiBarClientApp.Controllers } return View(APIClient.Client); } + [HttpPost] public void Privacy(string login, string password, string fio) { @@ -38,8 +40,7 @@ namespace SushiBarClientApp.Controllers { throw new Exception("Вы как суда попали? Суда вход только авторизованным"); } - if (string.IsNullOrEmpty(login) || - string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) + if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) { throw new Exception("Введите логин, пароль и ФИО"); } @@ -56,6 +57,7 @@ namespace SushiBarClientApp.Controllers APIClient.Client.Password = password; Response.Redirect("Index"); } + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { @@ -65,16 +67,17 @@ namespace SushiBarClientApp.Controllers Activity.Current?.Id ?? HttpContext.TraceIdentifier }); } + [HttpGet] public IActionResult Enter() { return View(); } + [HttpPost] public void Enter(string login, string password) { - if (string.IsNullOrEmpty(login) || - string.IsNullOrEmpty(password)) + if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password)) { throw new Exception("Введите логин и пароль"); } @@ -85,16 +88,17 @@ namespace SushiBarClientApp.Controllers } Response.Redirect("Index"); } + [HttpGet] public IActionResult Register() { return View(); } + [HttpPost] public void Register(string login, string password, string fio) { - if (string.IsNullOrEmpty(login) || - string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) + if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) { throw new Exception("Введите логин, пароль и ФИО"); } @@ -108,12 +112,14 @@ namespace SushiBarClientApp.Controllers Response.Redirect("Enter"); return; } + [HttpGet] public IActionResult Create() { ViewBag.Sushis = APIClient.GetRequest>("api/main/getsushilist"); return View(); } + [HttpPost] public void Create(int sushi, int count) { @@ -125,8 +131,7 @@ namespace SushiBarClientApp.Controllers { throw new Exception("Количество и сумма должны быть больше 0"); } - APIClient.PostRequest("api/main/createorder", new - OrderBindingModel + APIClient.PostRequest("api/main/createorder", new OrderBindingModel { ClientId = APIClient.Client.Id, SushiId = sushi, @@ -135,13 +140,23 @@ namespace SushiBarClientApp.Controllers }); Response.Redirect("Index"); } + [HttpPost] public double Calc(int count, int sushi) { - var _sushi = - APIClient.GetRequest($"api/main/getsushi?sushiid={sushi}" - ); + var _sushi = APIClient.GetRequest($"api/main/getsushi?sushiid={sushi}"); return Math.Round(count * (_sushi?.Price ?? 1), 2); } - } + + [HttpGet] + public IActionResult Mails() + { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + return + View(APIClient.GetRequest>($"api/client/getmessages?clientId={APIClient.Client.Id}")); + } + } } diff --git a/SushiBar/SushiBarClientApi/Views/Home/Mails.cshtml b/SushiBar/SushiBarClientApi/Views/Home/Mails.cshtml new file mode 100644 index 0000000..aa313fa --- /dev/null +++ b/SushiBar/SushiBarClientApi/Views/Home/Mails.cshtml @@ -0,0 +1,54 @@ +@using SushiBarContracts.ViewModels + +@model List + +@{ + ViewData["Title"] = "Mails"; +} + +
+

Заказы

+
+ + +
+ @{ + 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 diff --git a/SushiBar/SushiBarRestApi/Controllers/ClientController.cs b/SushiBar/SushiBarRestApi/Controllers/ClientController.cs index 14adf9d..a69e8af 100644 --- a/SushiBar/SushiBarRestApi/Controllers/ClientController.cs +++ b/SushiBar/SushiBarRestApi/Controllers/ClientController.cs @@ -12,11 +12,14 @@ namespace SushiBarRestApi.Controllers { private readonly ILogger _logger; private readonly IClientLogic _logic; - public ClientController(IClientLogic logic, ILogger logger) + private readonly IMessageInfoLogic _mailLogic; + public ClientController(IClientLogic logic, IMessageInfoLogic mailLogic, ILogger logger) { _logger = logger; _logic = logic; + _mailLogic = mailLogic; } + [HttpGet] public ClientViewModel? Login(string login, string password) { @@ -34,6 +37,24 @@ namespace SushiBarRestApi.Controllers throw; } } + + [HttpGet] + public List? GetMessages(int clientId) + { + try + { + return _mailLogic.ReadList(new MessageInfoSearchModel + { + ClientId = clientId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения писем клиента"); + throw; + } + } + [HttpPost] public void Register(ClientBindingModel model) { @@ -47,6 +68,7 @@ namespace SushiBarRestApi.Controllers throw; } } + [HttpPost] public void UpdateData(ClientBindingModel model) {