Esempio n. 1
0
        public IActionResult UpdateFood(Guid id, [FromBody] FoodUpdateDto foodItem)
        {
            if (foodItem == null)
            {
                return(BadRequest());
            }

            FoodItem existingFoodItem = _foodRepository.GetSingle(id);

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

            _mapper.Map(foodItem, existingFoodItem);

            _foodRepository.Update(existingFoodItem);

            if (!_foodRepository.Save())
            {
                throw new Exception("Updating a fooditem failed on save.");
            }

            _hubContext.Clients.All.SendAsync("food-updated", existingFoodItem);
            return(Ok(_mapper.Map <FoodItemDto>(existingFoodItem)));
        }
Esempio n. 2
0
        public IActionResult PartiallyUpdateFood(Guid id, [FromBody] JsonPatchDocument <FoodUpdateDto> patchDoc)
        {
            if (patchDoc == null)
            {
                return(BadRequest());
            }

            FoodItem foodItemFromRepo = _foodRepository.GetSingle(id);

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

            FoodUpdateDto foodItemToPatch = _mapper.Map <FoodUpdateDto>(foodItemFromRepo);

            patchDoc.ApplyTo(foodItemToPatch, ModelState);

            TryValidateModel(foodItemToPatch);

            _mapper.Map(foodItemToPatch, foodItemFromRepo);

            _foodRepository.Update(foodItemFromRepo);

            if (!_foodRepository.Save())
            {
                throw new Exception("Updating a fooditem failed on save.");
            }
            _hubContext.Clients.All.SendAsync("food-updated", _mapper.Map <FoodItemDto>(foodItemFromRepo));
            return(Ok(_mapper.Map <FoodItemDto>(foodItemFromRepo)));
        }
        public ActionResult <FoodItemDto> PartiallyUpdateFood(int id, [FromBody] JsonPatchDocument <FoodUpdateDto> patchDoc)
        {
            if (patchDoc == null)
            {
                return(BadRequest());
            }

            FoodItem existingEntity = _foodRepository.GetSingle(id);

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

            FoodUpdateDto foodUpdateDto = Mapper.Map <FoodUpdateDto>(existingEntity);

            patchDoc.ApplyTo(foodUpdateDto, ModelState);

            TryValidateModel(foodUpdateDto);

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

            Mapper.Map(foodUpdateDto, existingEntity);
            FoodItem updated = _foodRepository.Update(id, existingEntity);

            if (!_foodRepository.Save())
            {
                throw new Exception("Updating a fooditem failed on save.");
            }

            return(Ok(Mapper.Map <FoodItemDto>(updated)));
        }
        public ActionResult <FoodItemDto> UpdateFood(int id, [FromBody] FoodUpdateDto foodUpdateDto)
        {
            if (foodUpdateDto == null)
            {
                return(BadRequest());
            }

            var existingFoodItem = _foodRepository.GetSingle(id);

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

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

            Mapper.Map(foodUpdateDto, existingFoodItem);

            _foodRepository.Update(id, existingFoodItem);

            if (!_foodRepository.Save())
            {
                throw new Exception("Updating a fooditem failed on save.");
            }

            return(Ok(Mapper.Map <FoodItemDto>(existingFoodItem)));
        }
Esempio n. 5
0
        public async Task <string> Update(FoodUpdateDto input)
        {
            var Item = repository.GetSingel(input.Id);

            if (Item == null)
            {
                return("null");
            }
            repository.Update(new Entities.Models.Food()
            {
                Name        = input.Name,
                Fee         = input.Fee,
                RawMaterial = input.RawMaterial,
                MenueId     = input.MenueId
            });
            await repository.Save();

            return($"{input.Name} Was Upadated");
        }