Exemplo n.º 1
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 });
        }
Exemplo n.º 2
0
        public ActionResult AddtoBasket(int mealId, string email)
        {
            Basket basket = new Basket();
            Person person = new Person();
            using (var db = new MealPlanContext()) {
                person = db.Persons.First(p => p.Email == email);
                basket.MealId = mealId;
                basket.Person = person;
                db.Baskets.Add(basket);
                db.SaveChanges();
            }

            return Content("Ok");
        }
Exemplo n.º 3
0
        public ActionResult UserProfile(ProfileViewModel profile)
        {
            Sunddk.Utilities.Calculate utiliti = new Utilities.Calculate();
            double BMR = utiliti.CalculateBMR(profile.DateOfBirth, profile.Gender, profile.Weight, profile.Height);

            using (var db = new Models.MealPlanContext()) {
                Person person = new Person();
                Measurement measurements = new Measurement();
                person = db.Persons.FirstOrDefault(p => p.Email == profile.Email);
                measurements.Date = DateTime.Now;
                measurements.Weight = profile.Weight;
                measurements.Height = profile.Height;
                measurements.BMR = BMR;
                measurements.PersonId = person.PersonId;
                db.Measurements.Add(measurements);
                db.SaveChanges();

                return RedirectToAction("UserProfile", "User", new { Email = profile.Email});
            }
        }
Exemplo n.º 4
0
        public ActionResult UserProfile(string email)
        {
            using (var db = new Models.MealPlanContext()) {
                Person person = new Person();
                Measurement measurements = new Measurement();
                ProfileViewModel profile = new ProfileViewModel();
                person = db.Persons.First(p => p.Email == email);
                profile.Email = person.Email;
                profile.Name = person.Name;
                profile.DateOfBirth = person.DateOfBirth.Value.Date;
                profile.Gender = person.Gender;
                DateTime now = DateTime.Now.Date;
                measurements = db.Measurements.First(m => m.PersonId == person.PersonId /*&& m.Date == now*/);
                profile.Weight = measurements.Weight;
                profile.Height = measurements.Height;
                profile.BMR = measurements.BMR;

                return View(profile);
            }
        }