id, [FromBody]FoodUpdateDto foodUpda 3 { 4 if (foodUpdateDto == null) 5 { 6 return BadRequest(); 7 } 8 9 var existingFoodItem = _foodRepository.GetSingle(id); 10 11 if (existingFoodItem == null) 12 { 13 return NotFound(); 14 } 15 16 _mapper.Map(foodUpdateDto, existingFoodItem); 17 18 _foodRepository.Update(id, existingFoodItem); 19 20 if (!_foodRepository.Save()) 21 { 22 throw new Exception("Updating a fooditem failed on save."); 23 } 24 25 return Ok(_mapper.Map<FoodDto>(existingFoodItem)); 26 } 27 [Route("{id:int}", Name = nameof(UpdateFood))] [HttpPut] 1 2 public ActionResult<FoodDto> UpdateFood(int id, [FromBody]FoodUpdateDto foodUpda 3 { 4 if (foodUpdateDto == null) 5 { 6 return BadRequest(); 7 } 8 9 var existingFoodItem = _foodRepository.GetSingle(id); 10 11 if (existingFoodItem == null) 12 { 13 return NotFound(); 14 } 15 16 _mapper.Map(foodUpdateDto, existingFoodItem); 17 18 _foodRepository.Update(id, existingFoodItem); 19 20 if (!_foodRepository.Save()) 21 { 22 throw new Exception("Updating a fooditem failed on save."); 23 } 24 25 return Ok(_mapper.Map<FoodDto>(existingFoodItem)); 26 } 27 public ActionResult<FoodDto> UpdateFood(int id, [FromBody]FoodUpdateDto foodUpda [HttpPut] 1 [Route("{id:int}", Name = nameof(UpdateFood))] 2 3 { 4 if (foodUpdateDto == null) 5 { 6 return BadRequest(); 7 } 8 9 var existingFoodItem = _foodRepository.GetSingle(id); 10 11 if (existingFoodItem == null) 12 { 13 return NotFound(); 14 } 15 16 _mapper.Map(foodUpdateDto, existingFoodItem); 17 18 _foodRepository.Update(id, existingFoodItem); 19 20 if (!_foodRepository.Save()) 21 { 22 throw new Exception("Updating a fooditem failed on save."); 23 } 24 25 return Ok(_mapper.Map<FoodDto>(existingFoodItem)); 26 } 27 if (foodUpdateDto == null) { return BadRequest(); } [HttpPut] 1 [Route("{id:int}", Name = nameof(UpdateFood))] 2 public ActionResult<FoodDto> UpdateFood(int id, [FromBody]FoodUpdateDto foodUpda 3 { 4 5 6 7 8 9 var existingFoodItem = _foodRepository.GetSingle(id); 10 11 if (existingFoodItem == null) 12 { 13 return NotFound(); 14 } 15 16 _mapper.Map(foodUpdateDto, existingFoodItem); 17 18 _foodRepository.Update(id, existingFoodItem); 19 20 if (!_foodRepository.Save()) 21 { 22 throw new Exception("Updating a fooditem failed on save."); 23 } 24 25 return Ok(_mapper.Map<FoodDto>(existingFoodItem)); 26 } 27 var existingFoodItem = _foodRepository.GetSingle(id); if (existingFoodItem == null) { return NotFound(); } [HttpPut] 1 [Route("{id:int}", Name = nameof(UpdateFood))] 2 public ActionResult<FoodDto> UpdateFood(int id, [FromBody]FoodUpdateDto foodUpda 3 { 4 if (foodUpdateDto == null) 5 { 6 return BadRequest(); 7 } 8 9 10 11 12 13 14 15 16 _mapper.Map(foodUpdateDto, existingFoodItem); 17 18 _foodRepository.Update(id, existingFoodItem); 19 20 if (!_foodRepository.Save()) 21 { 22 throw new Exception("Updating a fooditem failed on save."); 23 } 24 25 return Ok(_mapper.Map<FoodDto>(existingFoodItem)); 26 } 27 _mapper.Map(foodUpdateDto, existingFoodItem); _foodRepository.Update(id, existingFoodItem); [HttpPut] 1 [Route("{id:int}", Name = nameof(UpdateFood))] 2 public ActionResult<FoodDto> UpdateFood(int id, [FromBody]FoodUpdateDto foodUpda 3 { 4 if (foodUpdateDto == null) 5 { 6 return BadRequest(); 7 } 8 9 var existingFoodItem = _foodRepository.GetSingle(id); 10 11 if (existingFoodItem == null) 12 { 13 return NotFound(); 14 } 15 16 17 18 19 20 if (!_foodRepository.Save()) 21 { 22 throw new Exception("Updating a fooditem failed on save."); 23 } 24 25 return Ok(_mapper.Map<FoodDto>(existingFoodItem)); 26 } 27 if (!_foodRepository.Save()) { throw new Exception("Updating a fooditem failed on save."); } [HttpPut] 1 [Route("{id:int}", Name = nameof(UpdateFood))] 2 public ActionResult<FoodDto> UpdateFood(int id, [FromBody]FoodUpdateDto foodUpda 3 { 4 if (foodUpdateDto == null) 5 { 6 return BadRequest(); 7 } 8 9 var existingFoodItem = _foodRepository.GetSingle(id); 10 11 if (existingFoodItem == null) 12 { 13 return NotFound(); 14 } 15 16 _mapper.Map(foodUpdateDto, existingFoodItem); 17 18 _foodRepository.Update(id, existingFoodItem); 19 20 21 22 23 24 25 return Ok(_mapper.Map<FoodDto>(existingFoodItem)); 26 } 27 return Ok(_mapper.Map<FoodDto>(existingFoodItem)); [HttpPut] 1 [Route("{id:int}", Name = nameof(UpdateFood))] 2 public ActionResult<FoodDto> UpdateFood(int id, [FromBody]FoodUpdateDto foodUpda 3 { 4 if (foodUpdateDto == null) 5 { 6 return BadRequest(); 7 } 8 9 var existingFoodItem = _foodRepository.GetSingle(id); 10 11 if (existingFoodItem == null) 12 { 13 return NotFound(); 14 } 15 16 _mapper.Map(foodUpdateDto, existingFoodItem); 17 18 _foodRepository.Update(id, existingFoodItem); 19 20 if (!_foodRepository.Save()) 21 { 22 throw new Exception("Updating a fooditem failed on save."); 23 } 24 25 26 } 27