public void Delete(int Id) { try { var entity = _entity.Where(c => c.Id == Id).FirstOrDefault(); if (entity != null) { _bikeStoresContext.Remove(entity); } } catch (Exception) { throw; } }
public async Task <Unit> Handle(Command request, CancellationToken cancellationToken) { var customer = await bikeStoresContext.Customers.FindAsync(request.Id); if (customer == null) { throw new Exception("no customer found to delete"); } bikeStoresContext.Remove(customer); var sucess = await bikeStoresContext.SaveChangesAsync() > 0; if (sucess) { return(Unit.Value); } throw new Exception("unable to save changes"); }