public async Task <IActionResult> DeleteOrder(int id) { var order = await _context.Orders.FindAsync(id); if (order == null) { return(NotFound()); } using (var transaction = _context.Database.BeginTransaction()) { try { var details = _context.OrderDetails.Where(o => order.OrderId == id); _context.OrderDetails.RemoveRange(details); _context.Remove(order); await transaction.CommitAsync(); } catch (Exception) { await transaction.RollbackAsync(); } await _context.SaveChangesAsync(); } return(NoContent()); }
public async Task <ActionResult> Delete([FromBody] CRUDModel <Orders> param) { Orders value = _context.Orders.Where(e => e.OrderID == Int32.Parse(param.Key.ToString())).FirstOrDefault(); _context.Remove(value); await _context.SaveChangesAsync(); return(Json(value)); }