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);
        }
Esempio n. 2
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});
            }
        }