diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/ProductStorage.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/ProductStorage.cs index df08917..96d263c 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/ProductStorage.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/ProductStorage.cs @@ -48,8 +48,10 @@ namespace ElectronicsShopDataBaseImplement.Implements { context.Products.Remove(element); context.SaveChanges(); - return element.GetViewModel; - } + return context.Products + .Include(x => x.CostItem) + .FirstOrDefault(x => x.ID == model.ID)?.GetViewModel; + } return null; } diff --git a/ElectronicsShop/ElectronicsShopEmployeeApp/Controllers/HomeController.cs b/ElectronicsShop/ElectronicsShopEmployeeApp/Controllers/HomeController.cs index d8f29ea..e619f5e 100644 --- a/ElectronicsShop/ElectronicsShopEmployeeApp/Controllers/HomeController.cs +++ b/ElectronicsShop/ElectronicsShopEmployeeApp/Controllers/HomeController.cs @@ -194,7 +194,19 @@ namespace ElectronicsShopEmployeeApp.Controllers { Response.Redirect("Index"); } + [HttpGet] + public IActionResult DeleteProduct(int id) { + var _product = APIEmployee.GetRequset($"api/main/getproduct?_productid={id}"); + if (_product == null) { + return Redirect("/Home/Index"); + } + + APIEmployee.PostRequest("api/employee/deleteproduct", new ProductBindingModel { + ID = id + }); + return RedirectToAction("Index"); + } [HttpPost] public double Calc(int costitem, double productprice) { diff --git a/ElectronicsShop/ElectronicsShopEmployeeApp/Views/Home/Index.cshtml b/ElectronicsShop/ElectronicsShopEmployeeApp/Views/Home/Index.cshtml index 3ee240a..9dc2f5e 100644 --- a/ElectronicsShop/ElectronicsShopEmployeeApp/Views/Home/Index.cshtml +++ b/ElectronicsShop/ElectronicsShopEmployeeApp/Views/Home/Index.cshtml @@ -54,7 +54,7 @@ Изменить - Удалить + Удалить } diff --git a/ElectronicsShop/ElectronicsShopRestAPI/Controllers/EmployeeController.cs b/ElectronicsShop/ElectronicsShopRestAPI/Controllers/EmployeeController.cs index a4f32ad..2983893 100644 --- a/ElectronicsShop/ElectronicsShopRestAPI/Controllers/EmployeeController.cs +++ b/ElectronicsShop/ElectronicsShopRestAPI/Controllers/EmployeeController.cs @@ -114,5 +114,16 @@ namespace ElectronicsShopRestAPI.Controllers { throw; } } + + [HttpPost] + public void DeleteProduct(ProductBindingModel model) { + try { + _productLogic.Delete(model); + } + catch (Exception ex) { + _logger.LogError(ex, "Ошибка удаления товара"); + throw; + } + } } }