Ejemplo n.º 1
0
        public IActionResult Add(IngredientForAddDto ingredientDto)
        {
            var ingredientToAdd = _mapper.Map <Ingredient>(ingredientDto);

            _repo.Add(ingredientToAdd);

            return(Ok());
        }
Ejemplo n.º 2
0
        public async Task <IngredientModel> Add(CreateIngredientModel model)
        {
            var ingredient = _mapper.Map <Persistance.Models.Ingredients>(model);
            await _repository.Add(ingredient);

            await _repository.SaveChanges();

            return(_mapper.Map <IngredientModel>(ingredient));
        }
Ejemplo n.º 3
0
        public async Task <int> Create(IngredientRequest request)
        {
            var userId = _userContextService.GetUserId;

            if (userId == null)
            {
                throw new ForbidException();
            }

            var newIngredient = _mapper.Map <Ingredient>(request);

            newIngredient.UserId = userId;

            await _ingredientsRepository.Add(newIngredient);

            return(newIngredient.Id);
        }
Ejemplo n.º 4
0
            public async Task <Result> Handle(AddIngredientCommand command)
            {
                var ingredient = new Ingredient(command.Title, command.Description, command.Slug);

                try
                {
                    await _ingredientsRepository.Add(ingredient);
                }
                catch (DbUpdateException /* ex */)
                {
                    //Log the error (uncomment ex variable name and write a log.
                    return(Result.Fail("Unable to save changes. " +
                                       "Try again, and if the problem persists " +
                                       "see your system administrator."));
                }

                return(Result.Ok());
            }