Example #1
0
        public IActionResult UpdateMealMacros([FromRoute] Guid userUid, [FromRoute] Guid dailyMealUid, [FromBody] MealMacrosForUpdateDto mealMacrosForUpdateDto)
        {
            var mealMacrosEntity = _macrosRepository.GetMealMacrosByUid(dailyMealUid);

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

            var finalMealMacrosDto = new MealMacrosDto()
            {
                UId       = dailyMealUid,
                CreatedOn = DateTime.Now,
                Protein   = mealMacrosForUpdateDto.Protein,
                Carbs     = mealMacrosForUpdateDto.Carbs,
                Fats      = mealMacrosForUpdateDto.Fats,
                MealName  = mealMacrosForUpdateDto.MealName,
                UserFk    = userUid
            };

            _mapper.Map(finalMealMacrosDto, mealMacrosEntity);
            _macrosRepository.Save();

            return(NoContent());
        }
Example #2
0
        public IActionResult AddMealMacros([FromRoute] Guid userUid, [FromBody] MealMacrosForCreationDto mealMacrosForCreationDto)
        {
            var finalMealMacrosDto = new MealMacrosDto()
            {
                UId       = Guid.NewGuid(),
                CreatedOn = DateTime.Now,
                Protein   = mealMacrosForCreationDto.Protein,
                Carbs     = mealMacrosForCreationDto.Carbs,
                Fats      = mealMacrosForCreationDto.Fats,
                MealName  = mealMacrosForCreationDto.MealName,
                UserFk    = userUid
            };

            var finalMealMacros = _mapper.Map <Entities.MealMacros>(finalMealMacrosDto);

            _macrosRepository.AddMealMacros(finalMealMacros);
            _macrosRepository.Save();

            return(CreatedAtRoute("GetDailyMealMacros", finalMealMacrosDto));
        }