コード例 #1
0
        public ActionResult EditUser(string userId)
        {
            var user = this.userManager.FindById(userId);
            if (user != null)
            {
                var viewModel = new UserViewModel
                {
                    Id = user.Id,
                    Username = user.UserName,
                    Email = user.Email,
                };
                return View(viewModel);
            }

            return base.DefaultError();
        }
コード例 #2
0
        public async Task<ActionResult> EditUser(UserViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var user = this.userManager.FindById(viewModel.Id);
                if (user != null)
                {
                    user.UserName = viewModel.Username;
                    user.Email = viewModel.Email;

                    var result = this.userManager.Update(user);
                    if (result.Succeeded)
                    {
                        if (User.Identity.GetUserId() == user.Id)
                        {
                            await SignInAsync(user, false);
                        }
                        return Redirect(UrlProvider<AccountController>.GetUrl(c => c.ManageUsers()));
                    }
                }
            }
            
            return View(viewModel);
        }
コード例 #3
0
        public ActionResult CreateUser(UserViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser
                {
                    UserName = viewModel.Username,
                    Email = viewModel.Email,
                };

                var password = PasswordGenerator.GeneratePassword();
                var result = this.userManager.Create(user, password);
                if (result.Succeeded)
                {
                    var roleResult = this.userManager.AddToRoles(user.Id, Role.GameDesigner);
                    if (roleResult.Succeeded)
                    {
                        this.SendEmailConfirmation(user.Id, user.UserName, password);
                        return Redirect(UrlProvider<AccountController>.GetUrl(c => c.ManageUsers()));
                    }
                }
            }
            return View(viewModel);
        }