public async Task Delete(int id) { var deleteIngredient = await _ingredientRepository.GetByIdAsync(id); if (deleteIngredient == null) { throw new EntityCantBeLoadedException <Ingredient>(id.ToString()); } await _ingredientRepository.DeleteAsync(deleteIngredient); }
public async Task <int> Handle(DeleteIngredientCommand request, CancellationToken cancellationToken) { var ingredient = repository.GetById(request.Id).Result; if (ingredient == null) { throw new Exception("Product doesn't exist"); } await repository.DeleteAsync(ingredient); return(ingredient.Id); }
public async Task <int> DeleteAsync(Guid id) { using (var connection = new SqlConnection(_connectionString)) { await connection.OpenAsync(); using (var transaction = await connection.BeginTransactionAsync()) { var rowsAffected = 0; rowsAffected += await _ingredientRepository.DeleteAsync ( connection, transaction, id ); rowsAffected += await _instructionRepository.DeleteAsync ( connection, transaction, id ); rowsAffected += await connection.ExecuteAsync(@" DELETE FROM [dbo].[Recipes] WHERE [Id] = @Id" , new { Id = id, }, transaction : transaction); return(rowsAffected); } } }
/// <summary> /// Remove one ingredient with its Id /// </summary> /// <param name="id">Int</param> /// <returns>bool</returns> public async Task <bool> RemoveIngredientById(int id) { _db.BeginTransaction(); IIngredientRepository _ingredients = _db.GetRepository <IIngredientRepository>(); try { var count = await _ingredients.DeleteAsync(id); _db.Commit(); return(count > 0); } catch (Exception e) { Trace.WriteLine(e); _db.Rollback(); return(false); } }
public async Task <int> Handle(DeleteIngredientCommand request, CancellationToken cancellationToken) { try { cancellationToken.ThrowIfCancellationRequested(); await Task.Delay(1000, cancellationToken); } catch (Exception ex) when(ex is TaskCanceledException) { throw new TaskCanceledException("The user has cancelled the task!"); } var ingredient = repository.GetById(request.Id).Result; if (ingredient == null) { throw new ArgumentNullException(nameof(request)); } await repository.DeleteAsync(ingredient); return(ingredient.Id); }
public async Task <Ingredient> DeleteIngredientAsync(int id) { return(await _ingredientRepository.DeleteAsync(id)); }