Example #1
0
 private static UserPageViewModel CreateUserViewModel(ApplicationUser appUser)
 {
     UserPageViewModel vm = new UserPageViewModel()
     {
         Username = appUser.UserName,
         Tweets = appUser.Tweets.OrderByDescending(x => x.DateCreated).ToList(),
         Tweet = new Tweet()
     };
     return vm;
 }
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var manager = new AuthenticationIdentityManager(new IdentityStore(new TvvitterContext()));
                // Create a local login before signing in the user
                var user = new ApplicationUser()
                {
                    UserName = model.UserName,
                };
                var result = manager.Users.CreateLocalUser(user, model.Password);
                //var result = await IdentityManager.Users.CreateLocalUserAsync(user, model.Password);
                if (result.Success)
                {
                    await IdentityManager.Authentication.SignInAsync(AuthenticationManager, user.Id, isPersistent: false);
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    AddErrors(result);
                }
            }

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