From a6b496e8e102403ea23f92b8c5709f598218f13f Mon Sep 17 00:00:00 2001 From: ValAnn Date: Tue, 9 Apr 2024 17:15:42 +0400 Subject: [PATCH] complete --- .../Controllers/HomeController.cs | 163 +++++++++++++++--- SushiBar/SushiBarClientApp/Program.cs | 20 +-- .../Views/Home/Create.cshtml | 50 ++++++ .../SushiBarClientApp/Views/Home/Enter.cshtml | 21 +++ .../SushiBarClientApp/Views/Home/Index.cshtml | 75 +++++++- .../Views/Home/Privacy.cshtml | 32 +++- .../Views/Home/Register.cshtml | 25 +++ .../Views/Shared/Error.cshtml | 2 +- .../Views/Shared/_Layout.cshtml | 18 +- SushiBar/SushiBarClientApp/appsettings.json | 2 +- .../Implements/OrderStorage.cs | 8 +- .../SushiBarDatabaseImplement/Models/Order.cs | 2 + .../DataFileSingleton.cs | 3 +- .../Implements/OrderStorage.cs | 6 +- .../SushiBarFileImplement/Models/Client.cs | 2 +- .../Controllers/MainController.cs | 19 +- .../Controllers/WeatherForecastController.cs | 33 ---- SushiBar/SushiBarRestApi/WeatherForecast.cs | 13 -- 18 files changed, 379 insertions(+), 115 deletions(-) create mode 100644 SushiBar/SushiBarClientApp/Views/Home/Create.cshtml create mode 100644 SushiBar/SushiBarClientApp/Views/Home/Enter.cshtml create mode 100644 SushiBar/SushiBarClientApp/Views/Home/Register.cshtml delete mode 100644 SushiBar/SushiBarRestApi/Controllers/WeatherForecastController.cs delete mode 100644 SushiBar/SushiBarRestApi/WeatherForecast.cs diff --git a/SushiBar/SushiBarClientApp/Controllers/HomeController.cs b/SushiBar/SushiBarClientApp/Controllers/HomeController.cs index ab45248..b39499e 100644 --- a/SushiBar/SushiBarClientApp/Controllers/HomeController.cs +++ b/SushiBar/SushiBarClientApp/Controllers/HomeController.cs @@ -1,32 +1,153 @@ using Microsoft.AspNetCore.Mvc; +using SushiBar.BindingModels; +using SushiBar.ViewModels; using SushiBarClientApp.Models; +using SushiBarContracts.BindingModels; +using SushiBarContracts.ViewModels; using System.Diagnostics; namespace SushiBarClientApp.Controllers { public class HomeController : Controller { - private readonly ILogger _logger; - - public HomeController(ILogger logger) - { - _logger = logger; + private readonly ILogger _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}")); + } + [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 + }); + 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("Введите логин и пароль"); + } + 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.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); + } } - public IActionResult Index() - { - return View(); - } - - public IActionResult Privacy() - { - return View(); - } - - [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] - public IActionResult Error() - { - return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); - } } -} + diff --git a/SushiBar/SushiBarClientApp/Program.cs b/SushiBar/SushiBarClientApp/Program.cs index 0727468..7af7aa1 100644 --- a/SushiBar/SushiBarClientApp/Program.cs +++ b/SushiBar/SushiBarClientApp/Program.cs @@ -1,27 +1,23 @@ +using SushiBarClientApp; +using Microsoft.EntityFrameworkCore.Infrastructure; +using SushiBarClientApp; var builder = WebApplication.CreateBuilder(args); - // Add services to the container. builder.Services.AddControllersWithViews(); - var app = builder.Build(); - +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. + // The default HSTS value is 30 days. You may want to change this for sushiion scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } - app.UseHttpsRedirection(); app.UseStaticFiles(); - app.UseRouting(); - app.UseAuthorization(); - app.MapControllerRoute( - name: "default", - pattern: "{controller=Home}/{action=Index}/{id?}"); - -app.Run(); + name: "default", + pattern: "{controller=Home}/{action=Index}/{id?}"); +app.Run(); \ No newline at end of file diff --git a/SushiBar/SushiBarClientApp/Views/Home/Create.cshtml b/SushiBar/SushiBarClientApp/Views/Home/Create.cshtml new file mode 100644 index 0000000..3045f71 --- /dev/null +++ b/SushiBar/SushiBarClientApp/Views/Home/Create.cshtml @@ -0,0 +1,50 @@ +@{ + ViewData["Title"] = "Create"; +} +
+

Создание заказа

+
+
+
+
Изделие:
+
+ +
+
+
+
Количество:
+
+
+
+
Сумма:
+
+
+
+
+
+
+
+ + \ No newline at end of file diff --git a/SushiBar/SushiBarClientApp/Views/Home/Enter.cshtml b/SushiBar/SushiBarClientApp/Views/Home/Enter.cshtml new file mode 100644 index 0000000..106d3d5 --- /dev/null +++ b/SushiBar/SushiBarClientApp/Views/Home/Enter.cshtml @@ -0,0 +1,21 @@ +@{ + ViewData["Title"] = "Enter"; +} + +
+

Вход в приложение

+
+
+
+
Логин:
+
+
+
+
Пароль:
+
+
+
+
+
+
+
\ No newline at end of file diff --git a/SushiBar/SushiBarClientApp/Views/Home/Index.cshtml b/SushiBar/SushiBarClientApp/Views/Home/Index.cshtml index d2d19bd..843135f 100644 --- a/SushiBar/SushiBarClientApp/Views/Home/Index.cshtml +++ b/SushiBar/SushiBarClientApp/Views/Home/Index.cshtml @@ -1,8 +1,75 @@ -@{ - ViewData["Title"] = "Home Page"; +@using SushiBarContracts.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.SushiName) + + @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 diff --git a/SushiBar/SushiBarClientApp/Views/Home/Privacy.cshtml b/SushiBar/SushiBarClientApp/Views/Home/Privacy.cshtml index af4fb19..3928c4e 100644 --- a/SushiBar/SushiBarClientApp/Views/Home/Privacy.cshtml +++ b/SushiBar/SushiBarClientApp/Views/Home/Privacy.cshtml @@ -1,6 +1,28 @@ -@{ - ViewData["Title"] = "Privacy Policy"; -} -

@ViewData["Title"]

+@using SushiBar.ViewModels +@using SushiBarContracts.ViewModels +@model ClientViewModel -

Use this page to detail your site's privacy policy.

+@{ + ViewData["Title"] = "Privacy Policy"; +} +
+

Личные данные

+
+
+
+
Логин:
+
+
+
+
Пароль:
+
+
+
+
ФИО:
+
+
+
+
+
+
+
\ No newline at end of file diff --git a/SushiBar/SushiBarClientApp/Views/Home/Register.cshtml b/SushiBar/SushiBarClientApp/Views/Home/Register.cshtml new file mode 100644 index 0000000..398b516 --- /dev/null +++ b/SushiBar/SushiBarClientApp/Views/Home/Register.cshtml @@ -0,0 +1,25 @@ +@{ + ViewData["Title"] = "Register"; +} + +
+

Регистрация

+
+
+
+
Логин:
+
+
+
+
Пароль:
+
+
+
+
ФИО:
+
+
+
+
+
+
+
\ No newline at end of file diff --git a/SushiBar/SushiBarClientApp/Views/Shared/Error.cshtml b/SushiBar/SushiBarClientApp/Views/Shared/Error.cshtml index a1e0478..4d96f6a 100644 --- a/SushiBar/SushiBarClientApp/Views/Shared/Error.cshtml +++ b/SushiBar/SushiBarClientApp/Views/Shared/Error.cshtml @@ -22,4 +22,4 @@ It can result in displaying sensitive information from exceptions to end users. For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development and restarting the app. -

+

\ No newline at end of file diff --git a/SushiBar/SushiBarClientApp/Views/Shared/_Layout.cshtml b/SushiBar/SushiBarClientApp/Views/Shared/_Layout.cshtml index 9a420a2..386e637 100644 --- a/SushiBar/SushiBarClientApp/Views/Shared/_Layout.cshtml +++ b/SushiBar/SushiBarClientApp/Views/Shared/_Layout.cshtml @@ -7,23 +7,31 @@ + +