diff --git a/PrecastConcretePlant/PrecastConcretePlantShopApp/APIClient.cs b/PrecastConcretePlant/PrecastConcretePlantShopApp/APIClient.cs index 5b0b339..6034be0 100644 --- a/PrecastConcretePlant/PrecastConcretePlantShopApp/APIClient.cs +++ b/PrecastConcretePlant/PrecastConcretePlantShopApp/APIClient.cs @@ -48,3 +48,4 @@ namespace PrecastConcretePlantShopApp } } } +} diff --git a/PrecastConcretePlant/PrecastConcretePlantShopApp/Controllers/HomeController.cs b/PrecastConcretePlant/PrecastConcretePlantShopApp/Controllers/HomeController.cs index 7ea2c8b..c61357b 100644 --- a/PrecastConcretePlant/PrecastConcretePlantShopApp/Controllers/HomeController.cs +++ b/PrecastConcretePlant/PrecastConcretePlantShopApp/Controllers/HomeController.cs @@ -1,32 +1,199 @@ using Microsoft.AspNetCore.Mvc; +using PrecastConcretePlantContracts.BindingModels; +using PrecastConcretePlantContracts.SearchModels; +using PrecastConcretePlantContracts.ViewModels; using PrecastConcretePlantShopApp.Models; using System.Diagnostics; namespace PrecastConcretePlantShopApp.Controllers { - public class HomeController : Controller - { - private readonly ILogger _logger; + public class HomeController : Controller + { + private readonly ILogger _logger; - public HomeController(ILogger logger) - { - _logger = logger; - } + public HomeController(ILogger logger) + { + _logger = logger; + } - public IActionResult Index() - { - return View(); - } + public IActionResult Index() + { + if (APIClient.IsAccessAllowed is false) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/shop/getshops")); + } - public IActionResult Privacy() - { - return View(); - } + [HttpGet] + public IActionResult Privacy() + { + if (APIClient.IsAccessAllowed is false) + { + return Redirect("~/Home/Enter"); + } + return View(); + } - [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(); + } + + [HttpPost] + public void Enter(string password) + { + if (string.IsNullOrEmpty(password)) + { + throw new Exception("Введите пароль"); + } + APIClient.IsAccessAllowed = password.Equals(APIClient.AccessPassword); + if (APIClient.IsAccessAllowed is false) + { + throw new Exception("Неверный пароль"); + } + Response.Redirect("Index"); + } + + [HttpGet] + public IActionResult Create() + { + return View(); + } + + [HttpPost] + public void Create(string name, string address, int maxCount) + { + if (APIClient.IsAccessAllowed is false) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + if (maxCount <= 0) + { + throw new Exception("Количество и сумма должны быть больше 0"); + } + if (string.IsNullOrEmpty(name)) + { + throw new Exception($"Имя магазина не должно быть пустым"); + } + if (string.IsNullOrEmpty(address)) + { + throw new Exception($"Адрес магазина не должен быть пустым"); + } + APIClient.PostRequest("api/shop/createshop", new ShopBindingModel + { + Name = name, + Address = address, + ReinforcedMaxCount = maxCount, + }); + Response.Redirect("Index"); + } + + [HttpGet] + public Tuple? GetTableReinforcediesFromShop(int shop) + { + var result = APIClient.GetRequest, IEnumerable>?>($"api/shop/getshopwithreinforcedies?id={shop}"); + if (result == null) + { + return null; + } + var shopModel = result.Item1; + var resultHtml = ""; + foreach (var (item, count) in result.Item2.Zip(result.Item3)) + { + resultHtml += ""; + resultHtml += $"{item?.ReinforcedName ?? string.Empty}"; + resultHtml += $"{item?.Price ?? 0}"; + resultHtml += $"{count}"; + resultHtml += ""; + } + return Tuple.Create(resultHtml, shopModel); + } + + [HttpGet] + public IActionResult Update() + { + ViewBag.Shops = APIClient.GetRequest>("api/shop/getshops"); + return View(); + } + + [HttpPost] + public void Update(int shop, string name, string address) + { + if (APIClient.IsAccessAllowed is false) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + if (string.IsNullOrEmpty(name)) + { + throw new Exception($"Имя магазина не должно быть пустым"); + } + if (string.IsNullOrEmpty(address)) + { + throw new Exception($"Адрес магазина не должен быть пустым"); + } + APIClient.PostRequest("api/shop/updateshop", new ShopBindingModel + { + Id = shop, + Name = name, + Address = address, + }); + Response.Redirect("Index"); + } + + [HttpGet] + public IActionResult Delete() + { + ViewBag.Shops = APIClient.GetRequest>("api/shop/getshops"); + return View(); + } + + [HttpPost] + public void Delete(int shop) + { + if (APIClient.IsAccessAllowed is false) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + APIClient.PostRequest("api/shop/deleteshop", new ShopBindingModel + { + Id = shop, + }); + Response.Redirect("Index"); + } + + [HttpGet] + public IActionResult AddReinforced() + { + ViewBag.Shops = APIClient.GetRequest>("api/shop/getshops"); + ViewBag.Reinforcedies = APIClient.GetRequest>("api/main/getreinforcedlist"); + return View(); + } + + [HttpPost] + public void AddReinforced(int shop, int reinforced, int count) + { + if (APIClient.IsAccessAllowed is false) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + if (count <= 0) + { + throw new Exception("Количество должно быть больше 0"); + } + APIClient.PostRequest("api/shop/addreinforcedinshop", Tuple.Create( + new ShopSearchModel() { Id = shop }, + new ReinforcedViewModel() { Id = reinforced }, + count + )); + Response.Redirect("Index"); + } + } } \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantShopApp/PrecastConcretePlantShopApp.csproj b/PrecastConcretePlant/PrecastConcretePlantShopApp/PrecastConcretePlantShopApp.csproj index c933858..44229d3 100644 --- a/PrecastConcretePlant/PrecastConcretePlantShopApp/PrecastConcretePlantShopApp.csproj +++ b/PrecastConcretePlant/PrecastConcretePlantShopApp/PrecastConcretePlantShopApp.csproj @@ -10,4 +10,8 @@ + + + + diff --git a/PrecastConcretePlant/PrecastConcretePlantShopApp/Program.cs b/PrecastConcretePlant/PrecastConcretePlantShopApp/Program.cs index 48c13cb..90da52c 100644 --- a/PrecastConcretePlant/PrecastConcretePlantShopApp/Program.cs +++ b/PrecastConcretePlant/PrecastConcretePlantShopApp/Program.cs @@ -1,3 +1,5 @@ +using PrecastConcretePlantShopApp; + var builder = WebApplication.CreateBuilder(args); // Add services to the container. diff --git a/PrecastConcretePlant/PrecastConcretePlantShopApp/Views/Home/AddReinforced.cshtml b/PrecastConcretePlant/PrecastConcretePlantShopApp/Views/Home/AddReinforced.cshtml new file mode 100644 index 0000000..88bbd8c --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantShopApp/Views/Home/AddReinforced.cshtml @@ -0,0 +1,33 @@ +@using PrecastConcretePlantDataModels.Models +@using PrecastConcretePlantContracts.ViewModels; + +@model Dictionary + +@{ + ViewData["Title"] = "AddReinforced"; +} +
+

Пополнения магазина изделием

+
+
+
+
Выбранный магазин:
+
+ +
+
+
+
Выбранное изделие:
+
+ +
+
+
+
Количество:
+
+
+
+
+
+
+
\ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantShopApp/Views/Home/Create.cshtml b/PrecastConcretePlant/PrecastConcretePlantShopApp/Views/Home/Create.cshtml new file mode 100644 index 0000000..30bb21e --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantShopApp/Views/Home/Create.cshtml @@ -0,0 +1,24 @@ +@{ + ViewData["Title"] = "Create"; +} +
+

Создание магазина

+
+
+
+
Название магазина:
+
+
+
+
Адрес магазина:
+
+
+
+
Максимальное кол-во изделий:
+
+
+
+
+
+
+
diff --git a/PrecastConcretePlant/PrecastConcretePlantShopApp/Views/Home/Delete.cshtml b/PrecastConcretePlant/PrecastConcretePlantShopApp/Views/Home/Delete.cshtml new file mode 100644 index 0000000..dec3c85 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantShopApp/Views/Home/Delete.cshtml @@ -0,0 +1,18 @@ +@{ + ViewData["Title"] = "Update"; +} +
+

Редактирование магазина

+
+
+
+
Выбранный магазин:
+
+ +
+
+
+
+
+
+
diff --git a/PrecastConcretePlant/PrecastConcretePlantShopApp/Views/Home/Enter.cshtml b/PrecastConcretePlant/PrecastConcretePlantShopApp/Views/Home/Enter.cshtml new file mode 100644 index 0000000..9c2eed6 --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantShopApp/Views/Home/Enter.cshtml @@ -0,0 +1,15 @@ +@{ + ViewData["Title"] = "Enter"; +} + +
+

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

+
+
+
+
Пароль:
+
+
+
+
+
\ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantShopApp/Views/Home/Index.cshtml b/PrecastConcretePlant/PrecastConcretePlantShopApp/Views/Home/Index.cshtml index d2d19bd..a5858d3 100644 --- a/PrecastConcretePlant/PrecastConcretePlantShopApp/Views/Home/Index.cshtml +++ b/PrecastConcretePlant/PrecastConcretePlantShopApp/Views/Home/Index.cshtml @@ -1,8 +1,66 @@ -@{ - ViewData["Title"] = "Home Page"; +@using PrecastConcretePlantContracts.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.Name) + + @Html.DisplayFor(modelItem => item.Address) + + @Html.DisplayFor(modelItem => item.DateOpening) + + @Html.DisplayFor(modelItem => item.ReinforcedMaxCount) +
+ }
diff --git a/PrecastConcretePlant/PrecastConcretePlantShopApp/Views/Home/Update.cshtml b/PrecastConcretePlant/PrecastConcretePlantShopApp/Views/Home/Update.cshtml new file mode 100644 index 0000000..dc1ad4d --- /dev/null +++ b/PrecastConcretePlant/PrecastConcretePlantShopApp/Views/Home/Update.cshtml @@ -0,0 +1,71 @@ +@using PrecastConcretePlantContracts.ViewModels; +@using PrecastConcretePlantDataModels.Models; + +@{ + ViewData["Title"] = "Update"; +} +
+

Редактирование магазина

+
+
+
+
Выбранный магазин:
+
+ +
+
+
+
Новое название магазина:
+
+
+
+
Адрес магазина:
+
+
+ + + + + + + + + + + +
+ Название изделия + + Цена + + Количество +
+ +
+
+
+
+
+ + \ No newline at end of file diff --git a/PrecastConcretePlant/PrecastConcretePlantShopApp/Views/Shared/_Layout.cshtml b/PrecastConcretePlant/PrecastConcretePlantShopApp/Views/Shared/_Layout.cshtml index b198feb..99d3693 100644 --- a/PrecastConcretePlant/PrecastConcretePlantShopApp/Views/Shared/_Layout.cshtml +++ b/PrecastConcretePlant/PrecastConcretePlantShopApp/Views/Shared/_Layout.cshtml @@ -7,23 +7,23 @@ + + +