public async Task <IActionResult> DeleteCustomerAsync(long id) { var customer = await context.FindAsync <Customer>(id); if (customer == null) { return(NotFound()); } context.Remove(customer); await context.SaveChangesAsync(); return(Ok()); }
public async Task <bool> DeleteCustomerAsync(int id) { //Extra hop to the database but keeps it nice and simple for this demo //Including orders since there's a foreign-key constraint and we need //to remove the orders in addition to the customer var customer = await _Context.Customers .Include(c => c.Orders) .SingleOrDefaultAsync(c => c.Id == id); _Context.Remove(customer); try { return(await _Context.SaveChangesAsync() > 0 ? true : false); } catch (System.Exception exp) { _Logger.LogError($"Error in {nameof(DeleteCustomerAsync)}: " + exp.Message); } return(false); }