Ejemplo n.º 1
0
        public IActionResult PutIngredient(EditIngredient viewModel)
        {
            var ingredient = mapper.Map(viewModel);

            service.UpdateIngredient(ingredient);
            return(RedirectToAction(nameof(GetIngredients)));
        }
        //==========================UPDATE INGREDIENT BY NAME===============================//


        public async Task <bool> UpdateIngredientByName([FromUri] string name, [FromBody] EditIngredient model)
        {
            var entity =
                _context
                .Ingredients
                .Single(e => e.Name == name);

            entity.Name = model.Name;

            return(await _context.SaveChangesAsync() == 1);
        }
Ejemplo n.º 3
0
 public Ingredient Map(EditIngredient model)
 {
     return(new Ingredient
     {
         Id = model.Id,
         Name = model.Name,
         IsSour = model.IsSour,
         IsSpicy = model.IsSpicy,
         IsSugary = model.IsSugary,
         IngredientTypeId = model.IngredientTypeId
     });
 }
Ejemplo n.º 4
0
        public async Task <IActionResult> Get(int id)
        {
            int userId;

            try
            {
                userId = IdentityHelper.GetUserId(User);
            }
            catch (UnauthorizedAccessException)
            {
                return(Unauthorized());
            }

            EditIngredient editIngredientDto = await _ingredientService.GetAsync(id, userId);

            if (editIngredientDto == null)
            {
                return(NotFound());
            }

            return(Ok(editIngredientDto));
        }
Ejemplo n.º 5
0
        public virtual HttpResponseMessage Put(Guid id, EditIngredient editIngredient)
        {
            Ingredient ingredient = ingredientService.Get(id);

            if (ingredient == null)
            {
                var notFoundError = new Error
                {
                    Code    = (int)HttpStatusCode.NotFound,
                    Message = Properties.Resources.IngredientNotFoundMessage
                };

                return(Request.CreateResponse(HttpStatusCode.NotFound, notFoundError));
            }
            AutoMapper.Map(editIngredient, ingredient);

            ingredientService.Edit(ingredient);

            IngredientDto ingredientDto = AutoMapper.Map <Ingredient, IngredientDto>(ingredient);

            return(Request.CreateResponse(HttpStatusCode.OK, ingredientDto));
        }