public async Task <ActionResult> UpdateDiet([FromBody] DietDataJson dietData)
        {
            var diet = await dietService.UpdateDiet(dietData);

            if (diet == null)
            {
                return(BadRequest());
            }
            return(Ok(diet.ApplicationUserId));
        }
        public async Task <IActionResult> CreateDiet([FromBody] DietDataJson dietData)
        {
            var diet = await dietService.CreateDiet(dietData);

            if (diet == null)
            {
                return(BadRequest());
            }

            return(Ok(diet));
        }
Exemplo n.º 3
0
        public async Task <Diet> UpdateDiet(DietDataJson dietData)
        {
            var user = await accountRepository.GetCurrentUser();

            Diet updateDiet = await dietRepository.GetDiet(user.Id);

            await dietRepository.ChangeDietsAndDimensionsStatus(user.Id);

            await AddDimendions(dietData.Arms, dietData.Chest, dietData.Waist, dietData.Thig, dietData.Buttocks, user);

            Diet newDiet = new Diet();

            if (dietData.DietTarget == 2)
            {
                newDiet.Kcal              = updateDiet.Kcal + 200;
                newDiet.Mass              = true;
                newDiet.WeightReduction   = false;
                newDiet.WeightMaintenance = false;
            }
            else if (dietData.DietTarget == 1)
            {
                if (user.isMale == true)
                {
                    if (updateDiet.Kcal > 1300)
                    {
                        newDiet.Kcal = updateDiet.Kcal - 100;
                    }
                    else
                    {
                        newDiet.Kcal = updateDiet.Kcal;
                    }
                    newDiet.Mass              = false;
                    newDiet.WeightReduction   = true;
                    newDiet.WeightMaintenance = false;
                }
            }
            else if (dietData.DietTarget == 0)
            {
                newDiet.Kcal              = updateDiet.Kcal;
                newDiet.Mass              = false;
                newDiet.WeightReduction   = false;
                newDiet.WeightMaintenance = true;
            }

            newDiet.Protein           = Convert.ToInt32(newDiet.Kcal * 0.3);
            newDiet.Fat               = Convert.ToInt32(newDiet.Kcal * 0.2);
            newDiet.Carbohydrates     = Convert.ToInt32(newDiet.Kcal * 0.5);
            newDiet.IsActive          = true;
            newDiet.ApplicationUserId = user.Id;
            newDiet.ApplicationUser   = user;
            newDiet.Date              = DateTime.Now;

            if (newDiet.WeightMaintenance == true)
            {
                await CreateMeal(4, newDiet.Kcal, newDiet);
            }
            else
            {
                await CreateMeal(5, newDiet.Kcal, newDiet);
            }

            await dietRepository.AddDiet(newDiet);

            user.Diets.Add(newDiet);
            await dietRepository.Save();

            return(newDiet);
        }
Exemplo n.º 4
0
        public async Task <Diet> CreateDiet(DietDataJson dietData)
        {
            Diet diet = new Diet();
            var  user = await accountRepository.GetCurrentUser();

            await AddDimendions(dietData.Arms, dietData.Chest, dietData.Waist, dietData.Thig, dietData.Buttocks, user);

            double caloricDemand = CountCaloricDemand(dietData.Weight, dietData.Height, dietData.Age, user.isMale) * dietData.DailyActivity;

            if (dietData.DietTarget == 2)
            {
                caloricDemand         += 300;
                diet.Kcal              = Convert.ToInt32(caloricDemand);
                diet.Protein           = Convert.ToInt32(caloricDemand * 0.3);
                diet.Fat               = Convert.ToInt32(caloricDemand * 0.2);
                diet.Carbohydrates     = Convert.ToInt32(caloricDemand * 0.5);
                diet.IsActive          = true;
                diet.ApplicationUserId = user.Id;
                diet.ApplicationUser   = user;
                diet.Date              = DateTime.Now;
                diet.Mass              = true;
                diet.WeightReduction   = false;
                diet.WeightMaintenance = false;
                diet.Weight            = (int)dietData.Weight;
            }
            else if (dietData.DietTarget == 1)
            {
                caloricDemand         -= 300;
                diet.Kcal              = Convert.ToInt32(caloricDemand);
                diet.Protein           = Convert.ToInt32(caloricDemand * 0.3);
                diet.Fat               = Convert.ToInt32(caloricDemand * 0.2);
                diet.Carbohydrates     = Convert.ToInt32(caloricDemand * 0.5);
                diet.IsActive          = true;
                diet.ApplicationUserId = user.Id;
                diet.ApplicationUser   = user;
                diet.Date              = DateTime.Now;
                diet.Mass              = false;
                diet.WeightReduction   = true;
                diet.WeightMaintenance = false;
                diet.Weight            = (int)dietData.Weight;
            }



            if (dietData.DietTarget == 0)
            {
                diet.Kcal              = Convert.ToInt32(caloricDemand);
                diet.Protein           = Convert.ToInt32(caloricDemand * 0.3);
                diet.Fat               = Convert.ToInt32(caloricDemand * 0.2);
                diet.Carbohydrates     = Convert.ToInt32(caloricDemand * 0.5);
                diet.IsActive          = true;
                diet.ApplicationUserId = user.Id;
                diet.ApplicationUser   = user;
                diet.Date              = DateTime.Now;
                diet.Mass              = false;
                diet.WeightReduction   = false;
                diet.WeightMaintenance = true;
                diet.Weight            = (int)dietData.Weight;
                await CreateMeal(4, caloricDemand, diet);
            }
            else
            {
                await CreateMeal(5, caloricDemand, diet);
            }
            await dietRepository.AddDiet(diet);

            user.Diets.Add(diet);
            await dietRepository.Save();

            return(diet);
        }