public ActionResult CreateMealPlan(MealPlanViewModel mealPlanView) { MealPlan mealPlan = new MealPlan(); using (var db = new Models.MealPlanContext()) { mealPlan.Name = mealPlanView.Name; mealPlan.MaxCalories = mealPlanView.MaxCalories; mealPlan.Description = mealPlanView.Description; mealPlan.IsAdmin = true; db.MealPlans.Add(mealPlan); db.SaveChanges(); mealPlan = db.MealPlans.First(m => m.Name == mealPlanView.Name); } return RedirectToAction("CreateMeal", "Admin", new { MealPlanId = mealPlan.MealPlanId }); }
public ActionResult CreateMeal(MealViewModel mealView) { Meal meal = new Meal(); MealPlan mealPlan = new MealPlan(); using (var db = new Models.MealPlanContext()) { mealPlan = db.MealPlans.First(m => m.MealPlanId == mealView.MealPlanId); meal.Name = mealView.Name; meal.Description = mealView.Description; meal.Calories = mealView.Calories; meal.Weight = mealView.Weight; meal.Type = mealView.Type; meal.MealPlans = new List<MealPlan>(); meal.MealPlans.Add(mealPlan); db.Meals.Add(meal); db.SaveChanges(); meal = db.Meals.First(m => m.Name == mealView.Name); meals.Add(meal); } return RedirectToAction("CreateMeal", "Admin", new { MealPlanId = mealView.MealPlanId}); }
public async Task<ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); //return RedirectToAction("Index", "Home"); //Noget jeg har tilføjet til koden!! Sunddk.Utilities.Calculate utilitie = new Utilities.Calculate(); double BMR = utilitie.CalculateBMR(model.DateOfBirth, model.Gender, model.Weight, model.Height); var measurment = new Models.Measurement(); measurment.Date = DateTime.Now.Date; measurment.Weight = model.Weight; measurment.Height = model.Height; measurment.BMR = BMR; using (var db = new Models.MealPlanContext()) { var Person = new Models.Person(); Person.Name = model.Name; Person.DateOfBirth = model.DateOfBirth; Person.IsAdmin = model.IsAdmin; Person.Gender = model.Gender; Person.Email = model.Email; Person.Password = model.Password; Person.Measurements = new List<Models.Measurement>(); Person.Measurements.Add(measurment); db.Persons.Add(Person); db.SaveChanges(); } return RedirectToAction("UserProfile", "User", new { Email = model.Email }); } AddErrors(result); } // If we got this far, something failed, redisplay form return View(model); }
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}); } }
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); }