Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
                }
            }
        }
Ejemplo n.º 4
0
        /// <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);
            }
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
 public async Task <Ingredient> DeleteIngredientAsync(int id)
 {
     return(await _ingredientRepository.DeleteAsync(id));
 }