Delete & Update is done

This commit is contained in:
Илья Федотов 2024-05-29 21:45:37 +04:00
parent 464635f0fe
commit c2b184de42
4 changed files with 28 additions and 3 deletions

View File

@ -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;
}

View File

@ -194,7 +194,19 @@ namespace ElectronicsShopEmployeeApp.Controllers {
Response.Redirect("Index");
}
[HttpGet]
public IActionResult DeleteProduct(int id) {
var _product = APIEmployee.GetRequset<ProductViewModel>($"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) {

View File

@ -54,7 +54,7 @@
</th>
<td>
<a class="btn btn-primary btn-sm" asp-action="EditProduct" asp-route-ID="@item.ID">Изменить</a>
<a class="btn btn-primary btn-sm" asp-action="Delete" asp-route-id="@item.ID">Удалить</a>
<a class="btn btn-primary btn-sm" asp-action="DeleteProduct" asp-route-ID="@item.ID">Удалить</a>
</td>
</tr>
}

View File

@ -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;
}
}
}
}