Exemplo n.º 1
0
        public IActionResult Add(AddNutritionPlanViewModel addNutritionPlanViewModel)
        {
            if (ModelState.IsValid)
            {
                NutritionPlan newNutritionPlan = new NutritionPlan
                {
                    Name        = addNutritionPlanViewModel.Name,
                    Description = addNutritionPlanViewModel.Description
                };

                context.NutritionPlans.Add(newNutritionPlan);
                context.SaveChanges();

                return(Redirect("/NutritionPlan"));
            }

            return(View(addNutritionPlanViewModel));
        }
Exemplo n.º 2
0
        public IActionResult Add(AddFoodViewModel addFoodViewModel)
        {
            if (ModelState.IsValid)
            {
                NutritionPlan newNutritionPlan = context.NutritionPlans.Single(n => n.ID == addFoodViewModel.NutritionPlanID);
                //Add new food to context and save it
                Food newFood = new Food
                {
                    Name          = addFoodViewModel.Name,
                    Price         = addFoodViewModel.Price,
                    NutritionPlan = newNutritionPlan
                };

                context.Foods.Add(newFood);
                context.SaveChanges();

                return(Redirect("/Food"));
            }
            return(View(addFoodViewModel));
        }