Beispiel #1
0
        public async Task <IActionResult> EditAccount(AccountEditAccountViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await this._userManager.FindByIdAsync(model.Id);

                if (user != null)
                {
                    user.FirstName   = model.FirstName;
                    user.LastName    = model.LastName;
                    user.Gendre      = model.Gendre;
                    user.DateOfBirth = model.DateOfBirth;
                    if (model.Password != null)
                    {
                        // This Method Hash password before assigning it to a user..
                        var password = this._userManager.PasswordHasher.HashPassword(user, model.Password);
                        user.PasswordHash = password;
                    }

                    var result = await this._userManager.UpdateAsync(user);

                    if (result.Succeeded)
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                    foreach (var error in result.Errors)
                    {
                        ModelState.AddModelError("", error.Description);
                    }
                }
            }

            return(View(model));
        }
Beispiel #2
0
        public async Task <IActionResult> EditAccount(string id)
        {
            if (!String.IsNullOrEmpty(id))
            {
                var user = await this._userManager.FindByIdAsync(id);

                if (user != null)
                {
                    var model = new AccountEditAccountViewModel()
                    {
                        Id          = user.Id,
                        FirstName   = user.FirstName,
                        LastName    = user.LastName,
                        DateOfBirth = user.DateOfBirth,
                        Email       = user.Email,
                        Gendre      = user.Gendre
                    };
                    return(View(model));
                }
            }
            return(RedirectToAction("Index", "Home"));
        }