Example #1
0
 public PersonMealPlanViewModel(PersonMealPlan personMealPlan, List<Meal> meals)
 {
     this.BeginDate = personMealPlan.BeginDate;
     this.EndDate = personMealPlan.EndDate;
     this.IsActive = personMealPlan.IsActive;
     this.Meals = meals;
 }
Example #2
0
        public ActionResult Done(string email)
        {
            MealPlan userMealPlan = new MealPlan();
            Person person = new Person();
            Basket basket = new Basket();

            PersonMealPlan personMealPlan = new PersonMealPlan();
            using (var db = new MealPlanContext()) {
                person = db.Persons.First(p => p.Email == email);
                userMealPlan.IsAdmin = false;
                db.MealPlans.Add(userMealPlan);
                foreach (var b in db.Baskets) {
                    if (person.PersonId == b.PersonId) {
                        foreach (var m in db.Meals) {
                            if (m.MealId == b.MealId) {
                                m.MealPlans.Add(userMealPlan);
                            }
                        }
                    }
                }
                personMealPlan.BeginDate = DateTime.Now.Date;
                personMealPlan.EndDate = DateTime.Now.Date;
                personMealPlan.IsActive = true;
                personMealPlan.MealPlan = userMealPlan;
                personMealPlan.Person = person;
                db.PersonMealPlans.Add(personMealPlan);
                db.SaveChanges();

                db.Baskets.RemoveRange(db.Baskets.Where(b => b.PersonId == person.PersonId));
                db.SaveChanges();
            }
            return RedirectToAction("UserProfile", "User", new { Email = email });
        }
Example #3
0
 public ActionResult CurrentMealPlan(string email)
 {
     PersonMealPlan personMealPlan = new PersonMealPlan();
     List<MealPlan> mealPlan = new List<MealPlan>();
     PersonMealPlanViewModel personMealPlanViewModel;
     using (var db = new Models.MealPlanContext()) {
         personMealPlan = db.PersonMealPlans.First(pmp => pmp.Person.Email == email && pmp.IsActive == true);
         mealPlan = db.MealPlans.Include(mp => mp.Meals).Where(mp => mp.MealPlanId == personMealPlan.MealPlan.MealPlanId).ToList();
         personMealPlanViewModel = new PersonMealPlanViewModel(personMealPlan, mealPlan[0].Meals);
     }
     return View(personMealPlanViewModel);
 }
Example #4
0
 public ActionResult List(string email)
 {
     List<MealPlan> mealplans = new List<MealPlan>();
     MealPlan userMealPlan = new MealPlan();
     PersonMealPlan personMealPlan = new PersonMealPlan();
     userMealPlan.IsAdmin = false;
     ViewBag.Email = email;
     using (var db = new Models.MealPlanContext()) {
         mealplans = db.MealPlans.Where(p => p.IsAdmin == true).ToList(); //Skal kunne hente ud sådan at det er indenfor de kalorier som man må få (BMR)
         personMealPlan = db.PersonMealPlans.FirstOrDefault(mp => mp.Person.Email == email && mp.IsActive == true);
         if (personMealPlan == null) {
             return View(mealplans);
         }
         else {
             personMealPlan.IsActive = false;
             db.SaveChanges();
         }
     }
     return View(mealplans);
 }