Ejemplo n.º 1
0
        public IActionResult RemoveIngredient(RemovePlannedIngredientViewModel rPIngredientViewModel)
        {
            if (ModelState.IsValid)
            {
                //context.SaveChanges();

                foreach (int id in rPIngredientViewModel.IngredientIDs)
                {
                    Ingredient ingredient = context.Ingredients.Single(i => i.ID == id);

                    ingredient.IsInCart = false;
                }
                context.SaveChanges();
            }

            return(Redirect("Index"));
        }
Ejemplo n.º 2
0
        public IActionResult Index(AddCategoryViewModel acvm)
        {
            if (ModelState.IsValid)
            {
                Category category = new Category
                {
                    Name = acvm.Name,
                };

                context.Categories.Add(category);
                context.SaveChanges();

                return(Redirect("/Manage/Index"));
            }

            return(View(acvm));
        }
Ejemplo n.º 3
0
        public IActionResult AddAMeal(AddMealViewModel addMealViewModel)
        {
            if (ModelState.IsValid)
            {
                Meal meal = new Meal()
                {
                    Name = addMealViewModel.Name,
                    Note = addMealViewModel.Note
                };

                meal.Ingredients = new List <Ingredient>();
                for (int i = 0; i < addMealViewModel.Ingredients.Count(); i++)
                {
                    if (!string.IsNullOrEmpty(addMealViewModel.Ingredients[i]) && addMealViewModel.Ingredients[i] != "")
                    {
                        Ingredient ingredient = new Ingredient()
                        {
                            //make it so that each ingredient is added as upper case(all)
                            //and check if already in db
                            Name       = addMealViewModel.Ingredients[i],
                            CategoryID = addMealViewModel.CategoryIDs[i]
                        };

                        meal.Ingredients.Add(ingredient);
                    }
                }

                context.Meals.Add(meal);
                context.SaveChanges();

                return(Redirect("/Manage/Index"));
            }

            AddMealViewModel newAddMealViewModel = new AddMealViewModel(context.Categories.ToList());

            return(View(newAddMealViewModel));
        }
Ejemplo n.º 4
0
        public ActionResult Create([Bind(Include = "TASK_LIST_MAPPING_ID, USER_ID, TASK_LISTS")] TaskListViewModel taskListViewModel)
        {
            if (ModelState.IsValid)
            {
                TaskListViewModel tlvm = db.TaskListViewModels.Where(m => m.TASK_LIST_MAPPING_ID == taskListViewModel.TASK_LIST_MAPPING_ID).SingleOrDefault();
                if (tlvm == null)
                {
                    db.TaskListViewModels.Add(taskListViewModel);
                    db.SaveChanges();
                }

                db.TaskLists.Add(new TaskList()
                {
                    TASK_LIST_MAPPING_ID = taskListViewModel.TASK_LIST_MAPPING_ID, LIST_NAME = "New List"
                });

                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View(taskListViewModel));
        }
Ejemplo n.º 5
0
        public IActionResult Index(PlanWeekViewModel planWeekViewModel)
        {
            if (ModelState.IsValid)
            {
                List <int> mealIDs = new List <int>();

                if (planWeekViewModel.SundayMealID != -1)
                {
                    PlannedMeal sunday = new PlannedMeal()
                    {
                        Day    = "Sunday",
                        MealID = planWeekViewModel.SundayMealID,
                    };

                    mealIDs.Add(planWeekViewModel.SundayMealID);

                    context.PlannedMeals.Add(sunday);
                }

                if (planWeekViewModel.MondayMealID != -1)
                {
                    PlannedMeal monday = new PlannedMeal()
                    {
                        Day    = "Monday",
                        MealID = planWeekViewModel.MondayMealID
                    };

                    mealIDs.Add(planWeekViewModel.MondayMealID);

                    context.PlannedMeals.Add(monday);
                }

                if (planWeekViewModel.TuesdayMealID != -1)
                {
                    PlannedMeal tuesday = new PlannedMeal()
                    {
                        Day    = "Tuesday",
                        MealID = planWeekViewModel.TuesdayMealID
                    };

                    mealIDs.Add(planWeekViewModel.TuesdayMealID);

                    context.PlannedMeals.Add(tuesday);
                }

                if (planWeekViewModel.WednesdayMealID != -1)
                {
                    PlannedMeal wednesday = new PlannedMeal()
                    {
                        Day    = "Wednesday",
                        MealID = planWeekViewModel.WednesdayMealID
                    };

                    mealIDs.Add(planWeekViewModel.WednesdayMealID);

                    context.PlannedMeals.Add(wednesday);
                }

                if (planWeekViewModel.ThursdayMealID != -1)
                {
                    PlannedMeal thursday = new PlannedMeal()
                    {
                        Day    = "Thursday",
                        MealID = planWeekViewModel.ThursdayMealID
                    };

                    mealIDs.Add(planWeekViewModel.ThursdayMealID);

                    context.PlannedMeals.Add(thursday);
                }

                if (planWeekViewModel.FridayMealID != -1)
                {
                    PlannedMeal friday = new PlannedMeal()
                    {
                        Day    = "Friday",
                        MealID = planWeekViewModel.FridayMealID
                    };

                    mealIDs.Add(planWeekViewModel.FridayMealID);

                    context.PlannedMeals.Add(friday);
                }

                if (planWeekViewModel.SaturdayMealID != -1)
                {
                    PlannedMeal Saturday = new PlannedMeal()
                    {
                        Day    = "Saturday",
                        MealID = planWeekViewModel.SaturdayMealID
                    };

                    mealIDs.Add(planWeekViewModel.SaturdayMealID);

                    context.PlannedMeals.Add(Saturday);
                }

                context.SaveChanges();


                List <Ingredient> ingredients = context.Ingredients.Where(x => mealIDs.Contains(x.MealID)).ToList();


                foreach (Ingredient ingredient in ingredients)
                {
                    ingredient.IsInCart = true;
                }
                context.SaveChanges();

                return(Redirect("/See/Index"));
            }

            PlanWeekViewModel pWVM = new PlanWeekViewModel(context.Meals.ToList());

            return(View(pWVM));
        }