public async Task <MealDto> UpdateMeal([FromForm] UpdateMealDto input) //update meal
        {
            var meal = await _mealRepo.GetAsync(input.Id);

            string uniqueFileName = GetMovieImageName(input.Image);

            meal.Update(input.Name, uniqueFileName, input.Price, input.Calory);
            var result = await _mealRepo.Update(meal);

            return(_mapper.Map <Meal, MealDto>(result));
        }
Exemplo n.º 2
0
        public async Task <MealDto> UpdateWithNames(UpdateMealDto input)
        {
            CheckUpdatePermission();
            //we can use Logger, it's defined in ApplicationService class.
            Logger.Info("Updating a meal for input: " + input);

            // retrieving a meal entity with given id using standard Get method of repositories.
            var meal = await Repository.GetAsync(input.Id);

            // Updating changed properties of the retrieved task entity.
            MapToEntity(input, meal);

            return(MapToEntityDto(meal));
        }
Exemplo n.º 3
0
        protected void MapToEntity(UpdateMealDto updateInput, Meal entity)
        {
            // Updating changed properties of the retrieved task entity.
            if (!string.IsNullOrEmpty(updateInput.Name))
            {
                entity.SetName(updateInput.Name);
            }
            entity.SetDate(updateInput.Date);

            entity.SetType(updateInput.Type);

            if (updateInput.Ingredients.Any())
            {
                var ingredients = _ingredientRepository.GetAll().Where(i => updateInput.Ingredients.Contains(i.Name)).ToList();

                entity.SetIngredients(
                    ObjectMapper.Map <List <Ingredient> >(ingredients)
                    );
            }
        }
Exemplo n.º 4
0
 public IActionResult Put(int id, [FromBody] UpdateMealDto model) =>
 _mapper.Map <MealUpdateModel>(model)
 .Map(x => _commandRepo.Update(id, x))
 .Map(x => AllOk(new { updated = x }))
 .Reduce(_ => NotFound(), error => error is RecordNotFound)
 .Reduce(_ => InternalServerError(), x => _logger.LogError(x.ToString()));