public async Task <ActionResult> ProductDelete(int productId) { var images = _productImage.FindAllAsync(x => x.ProductId == productId); foreach (var item in await images) { await _productImage.DeleteAsync(item); } var reviews = _review.FindAllAsync(x => x.ProductId == productId); foreach (var item in await reviews) { await _review.DeleteAsync(item); } var details = _orderDetail.FindAllAsync(x => x.ProductId == productId); foreach (var item in await details) { await _orderDetail.DeleteAsync(item); } await _product.DeleteByIdAsync(productId); return(Redirect("/trang-quan-tri/quan-ly-san-pham")); }
public async Task <IHttpActionResult> Delete(Guid id) { var result = await _productServices.DeleteByIdAsync(id); if (result) { // Return a response message with status code 204 (No Content) // To indicate that the operation was successful return(StatusCode(HttpStatusCode.NoContent)); } else { return(NotFound()); } }