示例#1
0
        public async Task <ActionResult> SetName(SetNameViewModel model)
        {
            ApplicationDbContext          _db;
            UserManager <ApplicationUser> _userManager;

            using (_db = new ApplicationDbContext())
            {
                using (_userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(_db)))
                {
                    if (ModelState.IsValid)
                    {
                        var user = await _userManager.FindByIdAsync(User.Identity.GetUserId());

                        if (user != null)
                        {
                            try
                            {
                                user.Fullname = model.FullName;
                                await _db.SaveChangesAsync();

                                return(RedirectToAction("Index", new { Message = ManageMessageId.SetFullNameSuccess }));
                            }
                            catch (Exception e)
                            {
                                AddErrors(new IdentityResult(e.Message));
                            }
                        }
                    }
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
示例#2
0
        public SetName(SetNameViewModel viewModel)
        {
            InitializeComponent();

            this.DataContext = viewModel;

            Closing += new System.ComponentModel.CancelEventHandler(Upgrade_Closing);
        }
示例#3
0
        public IActionResult UpdateName(SetNameViewModel user)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            try
            {
                User.SetName(user.Username);
                return(RedirectToAction("Info", "User"));
            }
            catch (SetFailedException ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(View());
            }
        }
示例#4
0
        public async Task <ActionResult> SetPassword(SetNameViewModel model)
        {
            if (ModelState.IsValid)
            {
                var result = await UserManager.AddPasswordAsync(User.Identity.GetUserId(), model.NewName);

                if (result.Succeeded)
                {
                    var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());

                    if (user != null)
                    {
                        await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);
                    }
                    return(RedirectToAction("Index", new { Message = ManageMessageId.SetPasswordSuccess }));
                }
                AddErrors(result);
            }

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