From 5cf3fea289977dbada280483062683c669962d68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D1=8F=D1=87=D0=B5=D1=81=D0=BB=D0=B0=D0=B2=20=D0=98?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Thu, 21 Mar 2024 21:00:28 +0400 Subject: [PATCH] fix --- Pizzeria/PizzeriaClientApp/APIClient.cs | 70 ++--- .../Controllers/HomeController.cs | 246 +++++++++--------- Pizzeria/PizzeriaClientApp/Program.cs | 11 +- .../Views/Home/Create.cshtml | 4 +- .../PizzeriaClientApp/Views/Home/Enter.cshtml | 2 +- .../PizzeriaClientApp/Views/Home/Index.cshtml | 2 +- .../Views/Home/Privacy.cshtml | 2 +- .../Views/Home/Register.cshtml | 2 +- .../Views/Shared/_Layout.cshtml | 2 +- .../Views/Shared/_Layout.cshtml.css | 41 +-- .../Controllers/MainController.cs | 132 +++++----- 11 files changed, 258 insertions(+), 256 deletions(-) diff --git a/Pizzeria/PizzeriaClientApp/APIClient.cs b/Pizzeria/PizzeriaClientApp/APIClient.cs index bc03a12..a929777 100644 --- a/Pizzeria/PizzeriaClientApp/APIClient.cs +++ b/Pizzeria/PizzeriaClientApp/APIClient.cs @@ -5,45 +5,45 @@ using System.Text; namespace PizzeriaClientApp { - public class APIClient - { - private static readonly HttpClient _client = new(); + public class APIClient + { + private static readonly HttpClient _client = new(); - public static ClientViewModel? Client { get; set; } = null; + public static ClientViewModel? Client { get; set; } = null; - public static void Connect(IConfiguration configuration) - { - _client.BaseAddress = new Uri(configuration["IPAddress"]); - _client.DefaultRequestHeaders.Accept.Clear(); - _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); - } + public static void Connect(IConfiguration configuration) + { + _client.BaseAddress = new Uri(configuration["IPAddress"]); + _client.DefaultRequestHeaders.Accept.Clear(); + _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); + } - public static T? GetRequest(string requestUrl) - { - var response = _client.GetAsync(requestUrl); - var result = response.Result.Content.ReadAsStringAsync().Result; - if (response.Result.IsSuccessStatusCode) - { - return JsonConvert.DeserializeObject(result); - } - else - { - throw new Exception(result); - } - } + public static T? GetRequest(string requestUrl) + { + var response = _client.GetAsync(requestUrl); + var result = response.Result.Content.ReadAsStringAsync().Result; + if (response.Result.IsSuccessStatusCode) + { + return JsonConvert.DeserializeObject(result); + } + else + { + throw new Exception(result); + } + } - public static void PostRequest(string requestUrl, T model) - { - var json = JsonConvert.SerializeObject(model); - var data = new StringContent(json, Encoding.UTF8, "application/json"); + public static void PostRequest(string requestUrl, T model) + { + var json = JsonConvert.SerializeObject(model); + var data = new StringContent(json, Encoding.UTF8, "application/json"); - var response = _client.PostAsync(requestUrl, data); + var response = _client.PostAsync(requestUrl, data); - var result = response.Result.Content.ReadAsStringAsync().Result; - if (!response.Result.IsSuccessStatusCode) - { - throw new Exception(result); - } - } - } + var result = response.Result.Content.ReadAsStringAsync().Result; + if (!response.Result.IsSuccessStatusCode) + { + throw new Exception(result); + } + } + } } diff --git a/Pizzeria/PizzeriaClientApp/Controllers/HomeController.cs b/Pizzeria/PizzeriaClientApp/Controllers/HomeController.cs index 0ff576b..0830c6b 100644 --- a/Pizzeria/PizzeriaClientApp/Controllers/HomeController.cs +++ b/Pizzeria/PizzeriaClientApp/Controllers/HomeController.cs @@ -8,140 +8,140 @@ namespace PizzeriaClientApp.Controllers { public class HomeController : Controller { - private readonly ILogger _logger; + private readonly ILogger _logger; - public HomeController(ILogger logger) - { - _logger = logger; - } + public HomeController(ILogger logger) + { + _logger = logger; + } - public IActionResult Index() - { - if (APIClient.Client == null) - { - return Redirect("~/Home/Enter"); - } - return View(APIClient.GetRequest>($"api/main/getorders?clientId={APIClient.Client.Id}")); - } + public IActionResult Index() + { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/main/getorders?clientId={APIClient.Client.Id}")); + } - [HttpGet] - public IActionResult Privacy() - { - if (APIClient.Client == null) - { - return Redirect("~/Home/Enter"); - } - return View(APIClient.Client); - } + [HttpGet] + public IActionResult Privacy() + { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.Client); + } - [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 - }); + [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"); - } + 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 }); - } + [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(); - } + [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"); - } + [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(); - } + [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; - } + [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.Products = APIClient.GetRequest>("api/main/getpizzalist"); - return View(); - } + [HttpGet] + public IActionResult Create() + { + ViewBag.Pizzas = APIClient.GetRequest>("api/main/getpizzalist"); + return View(); + } - [HttpPost] - public void Create(int product, 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, - PizzaId = product, - Count = count, - Sum = Calc(count, product) - }); - Response.Redirect("Index"); - } + [HttpPost] + public void Create(int pizza, 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, + PizzaId = pizza, + Count = count, + Sum = Calc(count, pizza) + }); + Response.Redirect("Index"); + } - [HttpPost] - public double Calc(int count, int product) - { - var prod = APIClient.GetRequest($"api/main/getpizza?pizzaId={product}"); - return count * (prod?.Price ?? 1); - } - } + [HttpPost] + public double Calc(int count, int pizza) + { + var piz = APIClient.GetRequest($"api/main/getpizza?pizzaId={pizza}"); + return count * (piz?.Price ?? 1); + } + } } diff --git a/Pizzeria/PizzeriaClientApp/Program.cs b/Pizzeria/PizzeriaClientApp/Program.cs index 7df121b..1d4be63 100644 --- a/Pizzeria/PizzeriaClientApp/Program.cs +++ b/Pizzeria/PizzeriaClientApp/Program.cs @@ -12,12 +12,13 @@ APIClient.Connect(builder.Configuration); // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { - app.UseExceptionHandler("/Home/Error"); - // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. - app.UseHsts(); + app.UseExceptionHandler("/Home/Error"); + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); } app.UseHttpsRedirection(); + app.UseStaticFiles(); app.UseRouting(); @@ -25,7 +26,7 @@ app.UseRouting(); app.UseAuthorization(); app.MapControllerRoute( - name: "default", - pattern: "{controller=Home}/{action=Index}/{id?}"); + name: "default", + pattern: "{controller=Home}/{action=Index}/{id?}"); app.Run(); \ No newline at end of file diff --git a/Pizzeria/PizzeriaClientApp/Views/Home/Create.cshtml b/Pizzeria/PizzeriaClientApp/Views/Home/Create.cshtml index a4a64e9..28b68d2 100644 --- a/Pizzeria/PizzeriaClientApp/Views/Home/Create.cshtml +++ b/Pizzeria/PizzeriaClientApp/Views/Home/Create.cshtml @@ -8,7 +8,7 @@
Изделие:
- +
@@ -40,7 +40,7 @@ $.ajax({ method: "POST", url: "/Home/Calc", - data: { count: count, pizza: pizza }, + data: { count: count, pizza: pizza }, success: function (result) { $("#sum").val(result); } diff --git a/Pizzeria/PizzeriaClientApp/Views/Home/Enter.cshtml b/Pizzeria/PizzeriaClientApp/Views/Home/Enter.cshtml index 9e09c6d..106d3d5 100644 --- a/Pizzeria/PizzeriaClientApp/Views/Home/Enter.cshtml +++ b/Pizzeria/PizzeriaClientApp/Views/Home/Enter.cshtml @@ -1,4 +1,4 @@ -@{ +@{ ViewData["Title"] = "Enter"; } diff --git a/Pizzeria/PizzeriaClientApp/Views/Home/Index.cshtml b/Pizzeria/PizzeriaClientApp/Views/Home/Index.cshtml index 8cee9ed..1da578b 100644 --- a/Pizzeria/PizzeriaClientApp/Views/Home/Index.cshtml +++ b/Pizzeria/PizzeriaClientApp/Views/Home/Index.cshtml @@ -1,4 +1,4 @@ -@using PizzeriaContracts.ViewModels +@using PizzeriaContracts.ViewModels @model List diff --git a/Pizzeria/PizzeriaClientApp/Views/Home/Privacy.cshtml b/Pizzeria/PizzeriaClientApp/Views/Home/Privacy.cshtml index 2969983..8045897 100644 --- a/Pizzeria/PizzeriaClientApp/Views/Home/Privacy.cshtml +++ b/Pizzeria/PizzeriaClientApp/Views/Home/Privacy.cshtml @@ -1,4 +1,4 @@ -@using PizzeriaContracts.ViewModels +@using PizzeriaContracts.ViewModels @model ClientViewModel diff --git a/Pizzeria/PizzeriaClientApp/Views/Home/Register.cshtml b/Pizzeria/PizzeriaClientApp/Views/Home/Register.cshtml index b18c3cf..398b516 100644 --- a/Pizzeria/PizzeriaClientApp/Views/Home/Register.cshtml +++ b/Pizzeria/PizzeriaClientApp/Views/Home/Register.cshtml @@ -1,4 +1,4 @@ -@{ +@{ ViewData["Title"] = "Register"; } diff --git a/Pizzeria/PizzeriaClientApp/Views/Shared/_Layout.cshtml b/Pizzeria/PizzeriaClientApp/Views/Shared/_Layout.cshtml index 90e6513..3834c03 100644 --- a/Pizzeria/PizzeriaClientApp/Views/Shared/_Layout.cshtml +++ b/Pizzeria/PizzeriaClientApp/Views/Shared/_Layout.cshtml @@ -44,7 +44,7 @@
- © 2023 - PizzeriaShowClientApp - Privacy + © 2023 - PizzeriaClientApp - Privacy
diff --git a/Pizzeria/PizzeriaClientApp/Views/Shared/_Layout.cshtml.css b/Pizzeria/PizzeriaClientApp/Views/Shared/_Layout.cshtml.css index a72cbea..947d5b5 100644 --- a/Pizzeria/PizzeriaClientApp/Views/Shared/_Layout.cshtml.css +++ b/Pizzeria/PizzeriaClientApp/Views/Shared/_Layout.cshtml.css @@ -2,47 +2,48 @@ for details on configuring this project to bundle and minify static web assets. */ a.navbar-brand { - white-space: normal; - text-align: center; - word-break: break-all; + white-space: normal; + text-align: center; + word-break: break-all; } a { - color: #0077cc; + color: #0077cc; } .btn-primary { - color: #fff; - background-color: #1b6ec2; - border-color: #1861ac; + color: #fff; + background-color: #1b6ec2; + border-color: #1861ac; } .nav-pills .nav-link.active, .nav-pills .show > .nav-link { - color: #fff; - background-color: #1b6ec2; - border-color: #1861ac; + color: #fff; + background-color: #1b6ec2; + border-color: #1861ac; } .border-top { - border-top: 1px solid #e5e5e5; + border-top: 1px solid #e5e5e5; } + .border-bottom { - border-bottom: 1px solid #e5e5e5; + border-bottom: 1px solid #e5e5e5; } .box-shadow { - box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05); + box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05); } button.accept-policy { - font-size: 1rem; - line-height: inherit; + font-size: 1rem; + line-height: inherit; } .footer { - position: absolute; - bottom: 0; - width: 100%; - white-space: nowrap; - line-height: 60px; + position: absolute; + bottom: 0; + width: 100%; + white-space: nowrap; + line-height: 60px; } diff --git a/Pizzeria/PizzeriaRestApi/Controllers/MainController.cs b/Pizzeria/PizzeriaRestApi/Controllers/MainController.cs index 5ccd86a..132e092 100644 --- a/Pizzeria/PizzeriaRestApi/Controllers/MainController.cs +++ b/Pizzeria/PizzeriaRestApi/Controllers/MainController.cs @@ -6,77 +6,77 @@ using PizzeriaContracts.ViewModels; namespace PizzeriaRestApi.Controllers { - [Route("api/[controller]/[action]")] - [ApiController] - public class MainController : Controller - { - private readonly ILogger _logger; + [Route("api/[controller]/[action]")] + [ApiController] + public class MainController : Controller + { + private readonly ILogger _logger; - private readonly IOrderLogic _order; + private readonly IOrderLogic _order; - private readonly IPizzaLogic _pizza; + private readonly IPizzaLogic _pizza; - public MainController(ILogger logger, IOrderLogic order, IPizzaLogic pizza) - { - _logger = logger; - _order = order; - _pizza = pizza; - } + public MainController(ILogger logger, IOrderLogic order, IPizzaLogic pizza) + { + _logger = logger; + _order = order; + _pizza = pizza; + } - [HttpGet] - public List? GetPizzaList() - { - try - { - return _pizza.ReadList(null); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка получения списка продуктов"); - throw; - } - } + [HttpGet] + public List? GetPizzaList() + { + try + { + return _pizza.ReadList(null); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка продуктов"); + throw; + } + } - [HttpGet] - public PizzaViewModel? GetPizza(int pizzaId) - { - try - { - return _pizza.ReadElement(new PizzaSearchModel { Id = pizzaId }); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка получения продукта по id={Id}", pizzaId); - throw; - } - } + [HttpGet] + public PizzaViewModel? GetPizza(int pizzaId) + { + try + { + return _pizza.ReadElement(new PizzaSearchModel { Id = pizzaId }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения продукта по id={Id}", pizzaId); + throw; + } + } - [HttpGet] - public List? GetOrders(int clientId) - { - try - { - return _order.ReadList(new OrderSearchModel { ClientId = clientId }); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка получения списка заказов клиента id={Id}", clientId); - throw; - } - } + [HttpGet] + public List? GetOrders(int clientId) + { + try + { + return _order.ReadList(new OrderSearchModel { ClientId = clientId }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка заказов клиента id={Id}", clientId); + throw; + } + } - [HttpPost] - public void CreateOrder(OrderBindingModel model) - { - try - { - _order.CreateOrder(model); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка создания заказа"); - throw; - } - } - } + [HttpPost] + public void CreateOrder(OrderBindingModel model) + { + try + { + _order.CreateOrder(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания заказа"); + throw; + } + } + } }