Пример #1
0
        public async Task <ActionResult> EditUserName(EditUserNameViewModel model)
        {
            ApplicationUser user = await UserManager.FindByNameAsync(User.Identity.Name);

            if (user != null)
            {
                user.UserName = model.Username;
                IdentityResult result = await UserManager.UpdateAsync(user);

                if (result.Succeeded)
                {
                    AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", "Щось пішло не так.");
                }
            }
            else
            {
                ModelState.AddModelError("", "Користувача не знайдено.");
            }

            return(View(model));
        }
Пример #2
0
        public ActionResult EditUserName([Bind(Include = "UserName")] EditUserNameViewModel editUserName)
        {
            if (!ModelState.IsValid)
            {
                return(View(editUserName));
            }

            return(RedirectToAction("Index"));
        }
Пример #3
0
        public async Task <ActionResult> UpdateName()
        {
            ApplicationUser user = db.Users.Find(User.Identity.GetUserId());

            EditUserNameViewModel model = new EditUserNameViewModel()
            {
                UserID = user.Id, FirstName = user.FirstName ?? "Error", LastName = user.LastName ?? "Error"
            };

            await this.FillViewBag();

            return(View(model));
        }
Пример #4
0
        public async Task <ActionResult> EditUserName()
        {
            ApplicationUser user = await UserManager.FindByNameAsync(User.Identity.Name);

            if (user != null)
            {
                EditUserNameViewModel model = new EditUserNameViewModel {
                    Username = user.UserName
                };
                return(View(model));
            }

            return(RedirectToAction("Index", "Manage"));
        }
        public async Task<ActionResult> EditUserName (EditUserNameViewModel model)
        {
            ApplicationUser user = await UserManager.FindByNameAsync(User.Identity.Name);
            if (user != null)
            {
                user.UserName = model.Username;                
                IdentityResult result = await UserManager.UpdateAsync(user);
                if (result.Succeeded)
                {
                    AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
                    
                    return RedirectToAction("Index", "Home");
                }
                else
                {
                    ModelState.AddModelError("", "Щось пішло не так.");
                }
            }
            else
            {
                ModelState.AddModelError("", "Користувача не знайдено.");
            }

            return View(model);
        }
        public async Task<ActionResult> EditUserName()
        {
            ApplicationUser user = await UserManager.FindByNameAsync(User.Identity.Name);
            if (user != null)
            {
                EditUserNameViewModel model = new EditUserNameViewModel { Username = user.UserName};
                return View(model);
            }

            return RedirectToAction("Index", "Manage");
        }