public async Task <Result> Handle(DeleteIngredientCommand command)
            {
                try
                {
                    var ingredient = await _ingredientsRepository.Get(command.Slug);

                    if (ingredient == null)
                    {
                        return(Result.Fail("Ingredient not found."));
                    }

                    await _ingredientsRepository.Delete(ingredient);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!_ingredientsRepository.Exists(command.Slug))
                    {
                        return(Result.Fail("Recipe not found."));
                    }
                    else
                    {
                        throw;
                    }
                }
                catch (DbUpdateException /* ex */)
                {
                    return(Result.Fail("Delete failed. Try again, and if the problem persists " +
                                       "see your system administrator."));
                }

                return(Result.Ok());
            }
Exemple #2
0
            public async Task <Result> Handle(UpdateIngredientCommand command)
            {
                var ingredient = new Ingredient(command.Title, command.Description, command.Slug);

                try
                {
                    await _ingredientsRepository.Update(ingredient);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!_ingredientsRepository.Exists(ingredient.Slug))
                    {
                        return(Result.Fail("Recipe not found."));
                    }
                    else
                    {
                        throw;
                    }
                }

                return(Result.Ok());
            }
Exemple #3
0
 public bool Exists(int id, int userId)
 {
     return(_ingredientsRepository.Exists(id, userId));
 }