Delete & Update is done
This commit is contained in:
parent
464635f0fe
commit
c2b184de42
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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>
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user