diff --git a/Confectionery/ConfectioneryClientApp/Controllers/HomeController.cs b/Confectionery/ConfectioneryClientApp/Controllers/HomeController.cs index 93c5adb..e40a17a 100644 --- a/Confectionery/ConfectioneryClientApp/Controllers/HomeController.cs +++ b/Confectionery/ConfectioneryClientApp/Controllers/HomeController.cs @@ -1,4 +1,7 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.ViewModels; using ConfectioneryClientApp.Models; +using ConfectioneryClientApp; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; @@ -7,26 +10,135 @@ namespace ConfectioneryClientApp.Controllers public class HomeController : Controller { private readonly ILogger _logger; - public HomeController(ILogger logger) { _logger = logger; } - public IActionResult Index() { - return View(); + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + return + View(APIClient.GetRequest>($"api/main/getorders?clientId={APIClient.Client.Id}")); } - + [HttpGet] public IActionResult Privacy() { - return View(); + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.Client); } - - [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + [HttpPost] + public void Privacy(string login, string password, string fio) + { + if (APIClient.Client == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + if (string.IsNullOrEmpty(login) || + string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) + { + throw new Exception("Введите логин, пароль и ФИО"); + } + APIClient.PostRequest("api/client/updatedata", new ClientBindingModel + { + Id = APIClient.Client.Id, + ClientFIO = fio, + Email = login, + Password = password + }); + APIClient.Client.ClientFIO = fio; + APIClient.Client.Email = login; + APIClient.Client.Password = password; + Response.Redirect("Index"); + } + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, + NoStore = true)] public IActionResult Error() { - return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); + return View(new ErrorViewModel + { + RequestId = + 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)) + { + throw new Exception("Введите логин и пароль"); + } + APIClient.Client = APIClient.GetRequest($"api/client/login?login={login}&password={password}"); + if (APIClient.Client == null) + { + throw new Exception("Неверный логин/пароль"); + } + 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)) + { + throw new Exception("Введите логин, пароль и ФИО"); + } + APIClient.PostRequest("api/client/register", new ClientBindingModel + { + ClientFIO = fio, + Email = login, + Password = password + }); + Response.Redirect("Enter"); + return; + } + [HttpGet] + public IActionResult Create() + { + ViewBag.Pastrys = APIClient.GetRequest>("api/main/getpastrylist"); + return View(); + } + [HttpPost] + public void Create(int pastry, int count) + { + if (APIClient.Client == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + if (count <= 0) + { + throw new Exception("Количество и сумма должны быть больше 0"); + } + APIClient.PostRequest("api/main/createorder", new OrderBindingModel + { + ClientId = APIClient.Client.Id, + PastryId = pastry, + Count = count, + Sum = Calc(count, pastry) + }); + Response.Redirect("Index"); + } + [HttpPost] + public double Calc(int count, int pastry) + { + var prod = APIClient.GetRequest($"api/main/getpastry?pastryId={pastry}"); + return count * (prod?.Price ?? 1); } } } diff --git a/Confectionery/ConfectioneryClientApp/Views/Home/Index.cshtml b/Confectionery/ConfectioneryClientApp/Views/Home/Index.cshtml index bcfd79a..8253383 100644 --- a/Confectionery/ConfectioneryClientApp/Views/Home/Index.cshtml +++ b/Confectionery/ConfectioneryClientApp/Views/Home/Index.cshtml @@ -1,8 +1,75 @@ -@{ - ViewData["Title"] = "Home Page"; +@using ConfectioneryContracts.ViewModels +@model List +@{ + ViewData["Title"] = "Home Page"; } -
-

Welcome

-

Learn about building Web apps with ASP.NET Core.

+

Заказы

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

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

+ return; + } +

+ Создать заказ +

+ + + + + + + + + + + + + @foreach (var item in Model) + { + + + + + + + + + } + +
+ Номер + + Изделие + + Дата создания + + Количество + + Сумма + + Статус +
+ @Html.DisplayFor(modelItem => + item.Id) + + @Html.DisplayFor(modelItem => + item.PastryName) + + @Html.DisplayFor(modelItem => + item.DateCreate) + + @Html.DisplayFor(modelItem => + item.Count) + + @Html.DisplayFor(modelItem => + item.Sum) + + @Html.DisplayFor(modelItem => + item.Status) +
+ } +
\ No newline at end of file