From 79d137fdc90b3eadfa19fea5e5d6c2f180b18314 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=BB=D1=8C=D1=8F=20=D0=A4=D0=B5=D0=B4=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Sat, 1 Jun 2024 02:22:06 +0400 Subject: [PATCH] Web edit --- .../Controllers/MainController.cs | 2 + .../Controllers/HomeController.cs | 27 +++++ .../Views/Home/EditOrder.cshtml | 103 ++++++++++++++++++ 3 files changed, 132 insertions(+) create mode 100644 ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/EditOrder.cshtml diff --git a/ElectronicsShop/ElectronicsShopRestAPI/Controllers/MainController.cs b/ElectronicsShop/ElectronicsShopRestAPI/Controllers/MainController.cs index be64200..4940f28 100644 --- a/ElectronicsShop/ElectronicsShopRestAPI/Controllers/MainController.cs +++ b/ElectronicsShop/ElectronicsShopRestAPI/Controllers/MainController.cs @@ -127,6 +127,8 @@ namespace ElectronicsShopRestAPI.Controllers { } } + + [HttpPost] public void AddProduct(List jslist) { diff --git a/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs b/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs index 6726a78..0eec094 100644 --- a/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs +++ b/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs @@ -128,6 +128,33 @@ namespace ElectronicsShopUserApp.Controllers { return RedirectToAction("Orders"); } + [HttpGet] + public IActionResult EditOrder(int id) { + if (APIClient.Client == null) { + return Redirect("~/Home/Enter"); + } + + var products = APIClient.GetRequset>>($"api/main/getorderproducts?_orderid={id}"); + + foreach (var pr in products) { + var product = JsonConvert.DeserializeObject(pr[0]); + int count = JsonConvert.DeserializeObject(pr[1]); + _productList.Add(product.ID, (product, count)); + } + + (int, Dictionary) tuple = (id, _productList); + return View(tuple); + } + + [HttpPost] + public void EditOrder(int sum, int id) { + if (sum <= 0) { + APIClient.PostRequest($"api/main/deleteorders", new OrderBindingModel { ID = id }); + } + + Response.Redirect("Orders"); + } + [HttpGet] public IActionResult OrderView() { if (APIClient.Client == null) { diff --git a/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/EditOrder.cshtml b/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/EditOrder.cshtml new file mode 100644 index 0000000..43543be --- /dev/null +++ b/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/EditOrder.cshtml @@ -0,0 +1,103 @@ +@using ElectronicsShopContracts.ViewModels +@using ElectronicsShopDataModels.Models + +@model (int, Dictionary) + +@{ + ViewData["Title"] = "EditOrder"; +} + +
+

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

+
+ + + +
+
+
+
+ +
+
+
+
+
Сумма:
+
+ +
+
+

+ Добавить товар +

+ + + + + + + + + + + @foreach (var item in Model.Item2) { + + + + + + + + + + + } + +
+ Номер + + Продукт + + Количество + + Сумма +
+ @Html.DisplayFor(modelItem => item.Key) + + @Html.DisplayFor(modelItem => item.Value.Item1.ProductName) + + @Html.DisplayFor(modelItem => item.Value.Item2) + + @Html.DisplayFor(modelItem => item.Value.Item1.Price) + + Удалить +
+
+
+
+ +
+
+
+ +
+ + \ No newline at end of file