public async Task <bool> Delete(string type, int id) { int numOfChanges = 0; int numOfExpectedChanges = 1;//for our VehicleMake record //A bit of duplicate looking code, but we want to make sure the type matches // a case before we do any work, and we want to make sure work has been done // before we save any changes. switch (type) { case "make": { VehicleMake makeToDelete = await _vehicleMakeRepository.GetAsync(id); IEnumerable <VehicleModel> modelsToDelete = await _vehicleModelRepository.FindAsync(x => x.VehicleMakeId == id); if (makeToDelete != null) { numOfExpectedChanges += modelsToDelete.Count(); _vehicleMakeRepository.Remove(makeToDelete); _vehicleModelRepository.RemoveRange(modelsToDelete); numOfChanges = await _vehicleMakeRepository.SaveChangesAsync(); } break; } case "model": { VehicleModel delete = await _vehicleModelRepository.GetAsync(id); if (delete != null) { numOfExpectedChanges = 1; _vehicleModelRepository.Remove(delete); numOfChanges = await _vehicleMakeRepository.SaveChangesAsync(); } break; } } //if we delete what we expect to delete return(numOfChanges == numOfExpectedChanges); }