Esempio n. 1
0
        public async Task <ActionResult> Edit(AccountViewModel model, string SelectedRole)
        {
            if (ModelState.IsValid)
            {
#if DEBUG
                Debug.WriteLine("Model is valid");
#endif
                var user = await _userManager.FindByIdAsync(model.Id);

                if (user != null)
                {
#if DEBUG
                    Debug.WriteLine("User is not null");
#endif

                    user.FIO                = model.FIO;
                    user.Position           = model.Position;
                    user.SetPasswordEnabled = model.SetPasswordEnabled;
                    user.LockoutEnabled     = model.LockoutEnabled;
                    await _userManager.UpdateAsync(user);

                    var roles = await _userManager.GetRolesAsync(model.Id);

                    await _userManager.RemoveFromRolesAsync(model.Id, roles.ToArray <string>());

                    var result = await _userManager.AddToRoleAsync(model.Id, SelectedRole);

                    if (result.Succeeded)
                    {
#if DEBUG
                        Debug.WriteLine("Role is added");
#endif
                        return(RedirectToAction("List"));
                    }
                }
            }
            return(View(model));
        }