예제 #1
0
        public async Task <IActionResult> Edit(string UserName, string password, string old_password)
        {
            var user = await UserMgr.GetUserAsync(HttpContext.User);

            if (user != null)
            {
                if (!string.IsNullOrEmpty(UserName))
                {
                    user.UserName = UserName;
                }
                else
                {
                    ModelState.AddModelError("", "Username cannot be empty");
                }

                if (!string.IsNullOrEmpty(password) && !string.IsNullOrEmpty(old_password))
                {
                    IdentityResult result = await UserMgr.ChangePasswordAsync(user, old_password, password);

                    if (result.Succeeded)
                    {
                        return(RedirectToAction("Dashboard"));
                    }
                    else
                    {
                        ViewBag.error = "Old passord is incorrect";
                    }
                    return(View(user));
                }

                if (!string.IsNullOrEmpty(UserName))
                {
                    IdentityResult result = await UserMgr.UpdateAsync(user);

                    if (result.Succeeded)
                    {
                        return(RedirectToAction("Dashboard"));
                    }
                    else
                    {
                        return(View(user));
                    }
                }
            }
            else
            {
                ModelState.AddModelError("", "User Not Found");
            }
            return(View(user));
        }