From 06baeba759bf231d12d8037b83759df79d44cc23 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: Wed, 29 May 2024 18:32:24 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A2=D1=80=D0=B0=D0=B1=D0=BB=D1=8B=20=D1=81?= =?UTF-8?q?=20=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=D0=BE=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogic/OrderLogic.cs | 11 ++-- .../Controllers/MainController.cs | 39 ++++++++++++- .../Controllers/HomeController.cs | 52 ++++++++++++++---- .../Home/{Create.cshtml => AddProduct.cshtml} | 8 +-- .../Views/Home/CreateOrder.cshtml | 55 +++++++++++++++++++ .../Views/Home/Index.cshtml | 2 +- 6 files changed, 142 insertions(+), 25 deletions(-) rename ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/{Create.cshtml => AddProduct.cshtml} (86%) create mode 100644 ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/CreateOrder.cshtml diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/OrderLogic.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/OrderLogic.cs index b8ee1d1..6c7be8f 100644 --- a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/OrderLogic.cs @@ -5,11 +5,7 @@ using ElectronicsShopContracts.StorageContracts; using ElectronicsShopContracts.ViewModels; using ElectronicsShopDataModels.Enums; using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; + namespace ElectronicsShopBusinessLogic.BusinessLogic { @@ -63,7 +59,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic { if (model == null) throw new ArgumentNullException(nameof(model)); _logger.LogInformation($"ReadElement. ID:{model.ID}"); - var element = _storage.GetElement(model); + var element = _storage.GetElement(model);//Не находит в бд if (element == null) { _logger.LogWarning("ReadElement. elementn not found"); @@ -72,5 +68,6 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic _logger.LogInformation($"ReadElement find. ID:{element.ID}"); return element; } - } + + } } diff --git a/ElectronicsShop/ElectronicsShopRestAPI/Controllers/MainController.cs b/ElectronicsShop/ElectronicsShopRestAPI/Controllers/MainController.cs index fa385ec..e8f9e22 100644 --- a/ElectronicsShop/ElectronicsShopRestAPI/Controllers/MainController.cs +++ b/ElectronicsShop/ElectronicsShopRestAPI/Controllers/MainController.cs @@ -78,5 +78,42 @@ namespace ElectronicsShopRestAPI.Controllers { throw; } } - } + [HttpGet] + public List? GetAddProduct(int _clientID,int _orderID) + { + try + { + return _order.ReadList(new OrderSearchModel + { + ID = _orderID, + ClientID = _clientID + + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка заказов клиента id = {Id} ", _clientID); + throw; + } + } + + + [HttpPost] + public void AddProduct(OrderBindingModel model) + { + try + { + var order=_order.ReadElement(new OrderSearchModel { ID = model.ID });//возвращает null + if (model != null&& order!=null) + { + order.ProductList = model.ProductList; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания заказа"); + throw; + } + } + } } diff --git a/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs b/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs index 7541e9c..b86e6f1 100644 --- a/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs +++ b/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs @@ -1,4 +1,5 @@ using ElectronicsShopContracts.BindingModels; +using ElectronicsShopContracts.SearchModels; using ElectronicsShopContracts.ViewModels; using ElectronicsShopDataModels.Models; using ElectronicsShopUserApp.Models; @@ -91,31 +92,26 @@ namespace ElectronicsShopUserApp.Controllers { } [HttpGet] - public IActionResult Create() { + public IActionResult CreateOrder() { ViewBag.Products = APIClient.GetRequset>("api/main/getproducts"); + return View(); } [HttpPost] - public void Create(OrderBindingModel order) { + public void CreateOrder(OrderBindingModel order) { if (APIClient.Client == null) { throw new Exception(" ? "); } - if (order.ProductList.Count <= 0) + if (order.ProductList.Count > 0) { throw new Exception(" 0"); } - APIClient.PostRequest("api/main/createorder", new OrderBindingModel - { - ClientID = APIClient.Client.ID, - Sum = Calc(order.ProductList), - ProductList = order.ProductList, - DateCreate = DateTime.Now, - }); + Response.Redirect("Index"); } [HttpPost] - private double Calc(Dictionary ProductList) + private double CalcAll(Dictionary ProductList) { Double Sum = 0; foreach (var ProductItem in ProductList) @@ -124,5 +120,37 @@ namespace ElectronicsShopUserApp.Controllers { } return Sum; } - } + [HttpPost] + public double CalcProduct(int count, int product) + { + var prod = + APIClient.GetRequset($"api/main/getproduct?productID={product}" + ); + return count * (prod?.Price ?? 1); + } + [HttpGet] + public IActionResult AddProduct() + { + ViewBag.Products = APIClient.GetRequset>("api/main/getproducts"); + return View(); + } + [HttpPost] + public void AddProduct(int count) + { + if (APIClient.Client == null) + { + throw new Exception(" ? "); + } + if (count <= 0) + { + throw new Exception(" 0"); + } + APIClient.PostRequest("api/main/addproduct", new OrderSearchModel + { + ID = 1, + ClientID=APIClient.Client.ID, + }); + Response.Redirect("CreateOrder"); + } + } } diff --git a/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/Create.cshtml b/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/AddProduct.cshtml similarity index 86% rename from ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/Create.cshtml rename to ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/AddProduct.cshtml index 74521e8..eecd9b7 100644 --- a/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/Create.cshtml +++ b/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/AddProduct.cshtml @@ -1,5 +1,5 @@ @{ - ViewData["Title"] = "Create"; + ViewData["Title"] = "Add Product"; }

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

@@ -31,7 +31,7 @@
- +
@@ -48,8 +48,8 @@ if (count && product) { $.ajax({ method: "POST", - url: "/Home/Calc", - data: { count: count, product: product }, + url: "/Home/CalcProduct", + data: { count: count, product: product.price }, success: function (result) { var roundedResult = parseFloat(result).toFixed(2); $("#sum").val(roundedResult); diff --git a/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/CreateOrder.cshtml b/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/CreateOrder.cshtml new file mode 100644 index 0000000..824051b --- /dev/null +++ b/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/CreateOrder.cshtml @@ -0,0 +1,55 @@ +@using ElectronicsShopContracts.ViewModels + +@model OrderViewModel +@{ + ViewData["Title"] = "Create Order"; +} + + + + +
+

Корзина

+ @{ + + + + + + + + + @if(Model!=null){ + @foreach (var item in Model.ProductList) + { + + + + + } + } + +
+ + Продукт + + Количество + + Сумма +
+ + @Html.DisplayFor(modelItem => item.Value.Item1.ProductName) + + @Html.DisplayFor(modelItem => item.Value.Item2) + + @Html.DisplayFor(modelItem => item.Value.Item1.Price*item.Value.Item2) +
+ } +
\ No newline at end of file diff --git a/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/Index.cshtml b/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/Index.cshtml index 7862015..c53b781 100644 --- a/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/Index.cshtml +++ b/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/Index.cshtml @@ -18,7 +18,7 @@ return; }

- Создать заказ + Создать заказ