コード例 #1
0
        public ActionResult UpdateIngredient(Guid id, IngredientUpdateDto ingredientUpdateDto)
        {
            var IngredientItem = _baseRepo.ingredient.GetIngredientById(id);

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

            _mapper.Map(ingredientUpdateDto, IngredientItem);
            _baseRepo.ingredient.UpdateIngredient(IngredientItem);
            _baseRepo.SaveChanges();

            return(NoContent());
        }
コード例 #2
0
        public IActionResult UpdateIngredientForFood(Guid foodId, Guid id, [FromBody] IngredientUpdateDto ingredient)
        {
            if (ingredient == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            FoodItem foodItem = _foodRepository.GetSingle(foodId);

            if (foodItem == null)
            {
                return(NotFound("FoodNotFound"));
            }

            var singleItem = _repository.GetAll().Where(x => x.FoodItem.Id == foodId && x.Id == id).FirstOrDefault();

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

            Mapper.Map(ingredient, singleItem);

            _repository.Update(singleItem);

            if (!_repository.Save())
            {
                throw new Exception("Updating an ingredient failed on save.");
            }

            var updatedIngredientDto = Mapper.Map <IngredientDto>(singleItem);

            _hubContext.Clients.All.SendAsync("ingredient-updated", foodId, updatedIngredientDto);

            return(Ok(updatedIngredientDto));
        }
コード例 #3
0
        public async Task <ActionResult> Update(IngredientUpdateDto command)
        {
            await CommandDispatcher.DispatchAsync(command);

            return(NoContent());
        }