From 44b11867c97ab7b8e3f57013140544bb1dbb4564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B3=D0=BE=D1=80=D1=8C=20=D0=93=D0=BE=D1=80=D0=B4?= =?UTF-8?q?=D0=B5=D0=B5=D0=B2?= <89176335310x@gmail.com> Date: Fri, 3 May 2024 21:53:27 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B0=D1=81=D1=82=D0=BE=D1=8F=D1=89?= =?UTF-8?q?=D0=B0=D1=8F=20=D1=81=D0=B2=D0=BE=D0=B1=D0=BE=D0=B4=D0=B0=20?= =?UTF-8?q?=D0=BD=D0=B0=D1=87=D0=B8=D0=BD=D0=B0=D0=B5=D1=82=D1=81=D1=8F=20?= =?UTF-8?q?=D0=BF=D0=BE=20=D1=82=D1=83=20=D1=81=D1=82=D0=BE=D1=80=D0=BE?= =?UTF-8?q?=D0=BD=D1=83=20=D0=BE=D1=82=D1=87=D0=B0=D1=8F=D0=BD=D0=B8=D1=8F?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/HomeController.cs | 231 +++++++++--------- 1 file changed, 121 insertions(+), 110 deletions(-) diff --git a/SushiBar/SushiBarClientApp/Controllers/HomeController.cs b/SushiBar/SushiBarClientApp/Controllers/HomeController.cs index 4bace62..d9a1e4a 100644 --- a/SushiBar/SushiBarClientApp/Controllers/HomeController.cs +++ b/SushiBar/SushiBarClientApp/Controllers/HomeController.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; using SushiBarClientApp.Models; using SushiBarContracts.BindingModel; using SushiBarContracts.BindingModels; @@ -9,133 +9,144 @@ namespace SushiBarClientApp.Controllers { public class HomeController : Controller { - private readonly ILogger _logger; - public HomeController(ILogger logger) - { - _logger = logger; - } - public IActionResult Index() - { - if (APIClient.Client == null) + private readonly ILogger _logger; + public HomeController(ILogger logger) { - return Redirect("~/Home/Enter"); + _logger = logger; } - return - View(APIClient.GetRequest>($"api/main/getorders?clientId={APIClient.Client.Id}")); - } - [HttpGet] - public IActionResult Privacy() - { - if (APIClient.Client == null) + public IActionResult Index() { - return Redirect("~/Home/Enter"); + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + return + View(APIClient.GetRequest>($"api/main/getorders?clientId={APIClient.Client.Id}")); } - return View(APIClient.Client); - } - [HttpPost] - public void Privacy(string login, string password, string fio) - { - if (APIClient.Client == null) + [HttpGet] + public IActionResult Privacy() { - throw new Exception(" ? "); + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.Client); } - if (string.IsNullOrEmpty(login) || - string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) + [HttpPost] + public void Privacy(string login, string password, string fio) { - throw new Exception(" , "); + 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"); } - APIClient.PostRequest("api/client/updatedata", new ClientBindingModel + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, + NoStore = true)] + public IActionResult Error() { - 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 - }); - } - [HttpGet] - public IActionResult Enter() - { - return View(); - } - [HttpPost] - public void Enter(string login, string password) - { - if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password)) - { - throw new Exception(" "); + return View(new ErrorViewModel + { + RequestId = + Activity.Current?.Id ?? HttpContext.TraceIdentifier + }); } - APIClient.Client = APIClient.GetRequest($"api/client/login?login={login}&password={password}"); - if (APIClient.Client == null) + [HttpGet] + public IActionResult Enter() { - throw new Exception(" /"); + return View(); } - 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)) + [HttpPost] + public void Enter(string login, string password) { - throw new Exception(" , "); + 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"); } - APIClient.PostRequest("api/client/register", new ClientBindingModel + [HttpGet] + public IActionResult Register() { - ClientFIO = fio, - Email = login, - Password = password - }); - 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) - { - if (APIClient.Client == null) - { - throw new Exception(" ? "); + return View(); } - if (count <= 0) + [HttpPost] + public void Register(string login, string password, string fio) { - throw new Exception(" 0"); + 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; } - APIClient.PostRequest("api/main/createorder", new OrderBindingModel + [HttpGet] + public IActionResult Create() { - ClientId = APIClient.Client.Id, - SushiId = sushi, - Count = count, - Sum = Calc(count, sushi) - }); - Response.Redirect("Index"); - } - [HttpPost] - public double Calc(int count, int sushi) - { - var prod = APIClient.GetRequest($"api/main/getsushi?sushiId={sushi}" - ); - return count * (prod?.Price ?? 1); + ViewBag.Sushis = + APIClient.GetRequest>("api/main/getsushilist"); + return View(); + } + [HttpPost] + public void Create(int sushi, 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, + SushiId = sushi, + Count = count, + Sum = Calc(count, sushi) + }); + Response.Redirect("Index"); + } + [HttpPost] + public double Calc(int count, int sushi) + { + var prod = + APIClient.GetRequest($"api/main/getsushi?sushiId={sushi}" + ); + return count * (prod?.Price ?? 1); + } } + } -} +