Exemplo n.º 1
0
        public ActionResult JoinHousehold(RegisterViewModel model/*, int inviteHouseholdId*/)
        {
            ApplicationDbContext db = new ApplicationDbContext();
            //RegisterViewModel model = new RegisterViewModel();

            var updatedUser = db.Users.Find(User.Identity.GetUserId());

            if (ModelState.IsValid)
            {

                updatedUser.FirstName = model.FirstName;
                updatedUser.LastName = model.LastName;
                updatedUser.Email = model.Email;
                updatedUser.UserName = model.Email;
                updatedUser.HouseholdId = model.HouseholdId;

                    db.Entry(updatedUser).State = EntityState.Modified;


                db.SaveChanges();
                return RedirectToAction("Dashboard", "Home");
            }

            

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Exemplo n.º 2
0
        //Get: Households/Join
        public ActionResult JoinHousehold(int inviteHouseholdId)
        {
            RegisterViewModel model = new RegisterViewModel();

            ApplicationDbContext db = new ApplicationDbContext();
            var user = db.Users.Find(User.Identity.GetUserId());

            Household HouseholdJoin = db.Households.FirstOrDefault(i => i.Id == inviteHouseholdId);


            model.HouseholdName = HouseholdJoin.Name;
            model.Email = user.Email;
            model.FirstName = user.FirstName;
            model.LastName = user.LastName;
            model.Password = user.PasswordHash;
            model.ConfirmPassword = user.PasswordHash;

            if (model.HouseholdId == null)
            {
                model.HouseholdId = HouseholdJoin.Id;
            }


            db.SaveChanges();
            return View(model);
        }
Exemplo n.º 3
0
        public ActionResult RegisterToJoinHousehold(int inviteHouseholdId, int invitationId, Guid guid)
        {
         
            RegisterViewModel model = new RegisterViewModel();

            ApplicationDbContext db = new ApplicationDbContext();
            var user = db.Users.Find(User.Identity.GetUserId());

            Household HouseholdJoin = db.Households.FirstOrDefault(i => i.Id == inviteHouseholdId);
            Invitation invited = db.Invitations.FirstOrDefault(i => i.Id == invitationId);
            
            invited.JoinCode = guid;

            model.HouseholdName = HouseholdJoin.Name;
            model.HouseholdId = HouseholdJoin.Id;
            model.Email = invited.ToEmail;


            db.SaveChanges();
            return View(model);
        }
Exemplo n.º 4
0
        public async Task<ActionResult> RegisterToJoinHousehold(RegisterViewModel model, int householdId)
        {
            
            if (ModelState.IsValid)
            {
               

                var user = new ApplicationUser
                {
                    UserName = model.Email,
                    Email = model.Email,
                    FirstName = model.FirstName,
                    LastName = model.LastName,
                    HouseholdId = householdId
                };

                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

               
                    return RedirectToAction("Dashboard", "Home");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Exemplo n.º 5
0
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {

                var db = new ApplicationDbContext();
                db.Households.Add(new Household { Name = model.HouseholdName });
                await db.SaveChangesAsync();


                var id = db.Households.ToList().OrderByDescending(h => h.Id).FirstOrDefault(h => h.Name == model.HouseholdName).Id;

                var user = new ApplicationUser
                {
                    UserName = model.Email,
                    Email = model.Email,
                    FirstName = model.FirstName,
                    LastName = model.LastName,
                    HouseholdId = id
                };

                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("Dashboard", "Home");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }