From 55e743f9159f3484f154776fcbc86ebaf1d74c50 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: Mon, 27 May 2024 18:36:13 +0400 Subject: [PATCH] Web client & employee --- .../Controllers/HomeController.cs | 25 ++++++++++++++++--- .../Views/Shared/_Layout.cshtml | 3 +++ .../ElectronicsShopRestAPI/Program.cs | 2 ++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/ElectronicsShop/ElectronicsShopEmployeeApp/Controllers/HomeController.cs b/ElectronicsShop/ElectronicsShopEmployeeApp/Controllers/HomeController.cs index e2e3747..9b484d2 100644 --- a/ElectronicsShop/ElectronicsShopEmployeeApp/Controllers/HomeController.cs +++ b/ElectronicsShop/ElectronicsShopEmployeeApp/Controllers/HomeController.cs @@ -91,12 +91,29 @@ namespace ElectronicsShopEmployeeApp.Controllers { [HttpGet] public IActionResult Create() { - ViewBag.Orders = APIEmployee.GetRequset>("api/main/getproductlist"); + ViewBag.Orders = APIEmployee.GetRequset>("api/main/getproductlist"); return View(); } - public void Create(OrderBindingModel order) { - throw new NotImplementedException(); + [HttpPost] + public void Create(int price, int costItem, string productName) { + if (APIEmployee.Employee == null) { + throw new Exception("Только для авторизованных"); + } + if (price <= 0) { + throw new Exception("Стоимость товара должна быть больше 0"); + } + APIEmployee.PostRequest("api/main/createproduct", new ProductBindingModel { + CostItemID = costItem, + ProductName = productName, + Price = Calc(price, costItem) + }); + Response.Redirect("Index"); } - } + + private double Calc(int price, int costItem) { + var _costItem = APIEmployee.GetRequset($"api/main/getcostitem?_employeeID={costItem}"); + return price * (_costItem?.Price ?? 1); + } + } } diff --git a/ElectronicsShop/ElectronicsShopEmployeeApp/Views/Shared/_Layout.cshtml b/ElectronicsShop/ElectronicsShopEmployeeApp/Views/Shared/_Layout.cshtml index 79bc9f7..5b2ad4b 100644 --- a/ElectronicsShop/ElectronicsShopEmployeeApp/Views/Shared/_Layout.cshtml +++ b/ElectronicsShop/ElectronicsShopEmployeeApp/Views/Shared/_Layout.cshtml @@ -31,6 +31,9 @@ + diff --git a/ElectronicsShop/ElectronicsShopRestAPI/Program.cs b/ElectronicsShop/ElectronicsShopRestAPI/Program.cs index d4a689f..831a84b 100644 --- a/ElectronicsShop/ElectronicsShopRestAPI/Program.cs +++ b/ElectronicsShop/ElectronicsShopRestAPI/Program.cs @@ -13,10 +13,12 @@ var builder = WebApplication.CreateBuilder(args); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle