diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/DataBase.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/DataBase.cs
index e4868b2..23bfaec 100644
--- a/ElectronicsShop/ElectronicsShopDataBaseImplement/DataBase.cs
+++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/DataBase.cs
@@ -12,7 +12,7 @@ namespace ElectronicsShopDataBaseImplement
optionsBuilder)
{
if (optionsBuilder.IsConfigured == false) {
- optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-E2VPEN3\SQLEXPRESS;Initial Catalog=ElectronicsShopDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
+ optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-O0N00SH\SQLEXPRESS;Initial Catalog=ElectronicsShopDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
}
base.OnConfiguring(optionsBuilder);
}
diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/ProductStorage.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/ProductStorage.cs
index a0b0560..df08917 100644
--- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/ProductStorage.cs
+++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/ProductStorage.cs
@@ -35,7 +35,9 @@ namespace ElectronicsShopDataBaseImplement.Implements
}
component.Update(model);
context.SaveChanges();
- return component.GetViewModel;
+ return context.Products
+ .Include(x => x.CostItem)
+ .FirstOrDefault(x => x.ID == model.ID)?.GetViewModel;
}
public ProductViewModel? Delete(ProductBindingModel model)
@@ -58,8 +60,10 @@ namespace ElectronicsShopDataBaseImplement.Implements
return null;
}
using var context = new Database();
- return context.Products.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ProductName) &&
- (model.ID.HasValue && x.ID == model.ID)))?.GetViewModel;
+ return context.Products
+ .Include(x => x.CostItem)
+ .FirstOrDefault(x => (!string.IsNullOrEmpty(model.ProductName) && x.ProductName == model.ProductName) ||
+ (model.ID.HasValue && x.ID == model.ID))?.GetViewModel;
}
public List GetFilteredList(ProductSearchModel model)
diff --git a/ElectronicsShop/ElectronicsShopEmployeeApp/Controllers/HomeController.cs b/ElectronicsShop/ElectronicsShopEmployeeApp/Controllers/HomeController.cs
index c83582a..d8f29ea 100644
--- a/ElectronicsShop/ElectronicsShopEmployeeApp/Controllers/HomeController.cs
+++ b/ElectronicsShop/ElectronicsShopEmployeeApp/Controllers/HomeController.cs
@@ -2,6 +2,7 @@ using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.ViewModels;
using ElectronicsShopEmployeeApp.Models;
using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.Rendering;
using System.Diagnostics;
namespace ElectronicsShopEmployeeApp.Controllers {
@@ -140,6 +141,61 @@ namespace ElectronicsShopEmployeeApp.Controllers {
Response.Redirect("Index");
}
+ [HttpGet]
+ public IActionResult EditProduct(int id) {
+ var _product = APIEmployee.GetRequset($"api/main/getproduct?_productid={id}");
+
+ if (_product == null) {
+ return Redirect("/Home/Index");
+ }
+
+ ViewBag.CostItems = APIEmployee.GetRequset>($"api/employee/getcostitems?_employeeid={APIEmployee.Employee.ID}");
+
+ var obj = new ProductViewModel {
+ ProductName = _product.ProductName,
+ CostItemID = _product.CostItemID,
+ Price = _product.Price,
+ ID = _product.ID
+ };
+
+ var _costitemLoad = (APIEmployee.GetRequset($"api/employee/getcostitem?_costitemid={obj.CostItemID}"));
+
+ if (_costitemLoad?.Name != ViewBag.CostItems[0].Name) {
+ int index = 0;
+
+ for (int i = 0; i < ViewBag.CostItems.Count; i++) {
+ if (ViewBag.CostItems[i].Name == _costitemLoad?.Name) {
+ index = i;
+ break;
+ }
+ }
+
+ var tmp = ViewBag.CostItems[0];
+ ViewBag.CostItems[0] = _costitemLoad;
+ ViewBag.CostItems[index] = tmp;
+ }
+ return View(obj);
+ }
+
+ [HttpPost]
+ public void EditProduct(string name, int costitem, double productprice, int _ID) {
+ if (APIEmployee.Employee == null) {
+ throw new Exception(" ");
+ }
+ if (productprice <= 0) {
+ throw new Exception(" 0");
+ }
+ APIEmployee.PostRequest("api/employee/editproduct", new ProductBindingModel {
+ ID = _ID,
+ CostItemID = costitem,
+ ProductName = name,
+ Price = Calc(costitem, productprice)
+ });
+ Response.Redirect("Index");
+ }
+
+
+
[HttpPost]
public double Calc(int costitem, double productprice) {
var _costItem = APIEmployee.GetRequset($"api/employee/getcostitem?_costitemid={costitem}");
diff --git a/ElectronicsShop/ElectronicsShopEmployeeApp/Views/Home/CostItem.cshtml b/ElectronicsShop/ElectronicsShopEmployeeApp/Views/Home/CostItem.cshtml
index 69c48aa..b8b928e 100644
--- a/ElectronicsShop/ElectronicsShopEmployeeApp/Views/Home/CostItem.cshtml
+++ b/ElectronicsShop/ElectronicsShopEmployeeApp/Views/Home/CostItem.cshtml
@@ -25,7 +25,7 @@
Изменить
- Удалить
+ Удалить
diff --git a/ElectronicsShop/ElectronicsShopEmployeeApp/Views/Home/CreateCostItem.cshtml b/ElectronicsShop/ElectronicsShopEmployeeApp/Views/Home/CreateCostItem.cshtml
index 1200a0f..eb31ac6 100644
--- a/ElectronicsShop/ElectronicsShopEmployeeApp/Views/Home/CreateCostItem.cshtml
+++ b/ElectronicsShop/ElectronicsShopEmployeeApp/Views/Home/CreateCostItem.cshtml
@@ -27,7 +27,7 @@
diff --git a/ElectronicsShop/ElectronicsShopEmployeeApp/Views/Home/EditProduct.cshtml b/ElectronicsShop/ElectronicsShopEmployeeApp/Views/Home/EditProduct.cshtml
new file mode 100644
index 0000000..cd86060
--- /dev/null
+++ b/ElectronicsShop/ElectronicsShopEmployeeApp/Views/Home/EditProduct.cshtml
@@ -0,0 +1,74 @@
+@using ElectronicsShopContracts.ViewModels
+
+@model ProductViewModel
+
+@{
+ ViewData["Title"] = "EditProduct";
+}
+
+
+
Создание товара
+
+
+
+
\ No newline at end of file
diff --git a/ElectronicsShop/ElectronicsShopEmployeeApp/Views/Home/Index.cshtml b/ElectronicsShop/ElectronicsShopEmployeeApp/Views/Home/Index.cshtml
index 1b5e671..3ee240a 100644
--- a/ElectronicsShop/ElectronicsShopEmployeeApp/Views/Home/Index.cshtml
+++ b/ElectronicsShop/ElectronicsShopEmployeeApp/Views/Home/Index.cshtml
@@ -20,12 +20,6 @@
Создать товар
-
- Изменить
-
-
- Удалить
-
@@ -58,6 +52,10 @@
@Html.DisplayFor(modelItem => item.Price)
|
+
+ Изменить
+ Удалить
+ |
}
diff --git a/ElectronicsShop/ElectronicsShopRestAPI/Controllers/EmployeeController.cs b/ElectronicsShop/ElectronicsShopRestAPI/Controllers/EmployeeController.cs
index d29857b..a4f32ad 100644
--- a/ElectronicsShop/ElectronicsShopRestAPI/Controllers/EmployeeController.cs
+++ b/ElectronicsShop/ElectronicsShopRestAPI/Controllers/EmployeeController.cs
@@ -99,7 +99,18 @@ namespace ElectronicsShopRestAPI.Controllers {
_productLogic.Create(model);
}
catch(Exception ex) {
- _logger.LogError(ex, "Ошибка создания заказа");
+ _logger.LogError(ex, "Ошибка создания товара");
+ throw;
+ }
+ }
+
+ [HttpPost]
+ public void EditProduct(ProductBindingModel model) {
+ try {
+ _productLogic.Update(model);
+ }
+ catch (Exception ex) {
+ _logger.LogError(ex, "Ошибка обновления товара");
throw;
}
}
diff --git a/ElectronicsShop/ElectronicsShopRestAPI/Controllers/MainController.cs b/ElectronicsShop/ElectronicsShopRestAPI/Controllers/MainController.cs
index fa385ec..ed29eee 100644
--- a/ElectronicsShop/ElectronicsShopRestAPI/Controllers/MainController.cs
+++ b/ElectronicsShop/ElectronicsShopRestAPI/Controllers/MainController.cs
@@ -34,18 +34,18 @@ namespace ElectronicsShopRestAPI.Controllers {
}
}
[HttpGet]
- public ProductViewModel? GetPoduct(int productID)
+ public ProductViewModel? GetProduct(int _productID)
{
try
{
return _product.ReadElement(new ProductSearchModel
{
- ID = productID
+ ID = _productID
});
}
catch (Exception ex)
{
- _logger.LogError(ex, "Ошибка получения суши по id={Id}", productID);
+ _logger.LogError(ex, "Ошибка получения товаров id={Id}", _productID);
throw;
}
}