public async Task <ActionResult> ChangeDepartment(ChangeDepartmentModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await UserManager.FindByIdAsync(model.UserId);

                if (user == null)
                {
                    ModelState.AddModelError("", "Usuário não encontrado");
                }
                else
                {
                    user.DepartmentId = model.DepartmentId;
                    var result = await UserManager.UpdateAsync(user);

                    if (result.Succeeded)
                    {
                        return(RedirectToAction("Index", new { userId = model.UserId, message = ManageMessageId.DepartmentChanged }));
                    }

                    AddErrors(result);
                }
            }

            ViewBag.Roles = RoleList.CreateSelectableList(Database);
            return(View(model));
        }
        public async Task <ActionResult> ChangeRole(string userId)
        {
            var user = await UserManager.FindByIdAsync(userId);

            var model = new ChangeRoleModel();

            if (user == null)
            {
                ModelState.AddModelError("", "Usuário não encontrado");
            }
            else
            {
                model.Role   = user.Roles.FirstOrDefault().RoleId ?? "";
                model.UserId = userId;
            }

            var r = RoleList.CreateSelectableList(Database);

            //foreach (var role in r)
            //{
            //    role.Selected = (role.Text == model.Role);
            //}
            ViewBag.Roles = r;

            return(View(model));
        }
        public async Task <ActionResult> ChangeRole(ChangeRoleModel model)
        {
            if (ModelState.IsValid)
            {
                var roles = await UserManager.GetRolesAsync(model.UserId);

                var roleFound = Database.Roles.Find(model.Role);

                foreach (var role in roles)
                {
                    await UserManager.RemoveFromRoleAsync(model.UserId, role);
                }

                await UserManager.AddToRoleAsync(model.UserId, roleFound.Name);

                return(RedirectToAction("Index", new { userId = model.UserId, message = ManageMessageId.RoleChanged }));
            }

            ViewBag.Roles = RoleList.CreateSelectableList(Database);
            return(View(model));
        }
 public ActionResult Register()
 {
     ViewBag.Departments = DepartamentList.CreateSelectableList(Database);
     ViewBag.Roles       = RoleList.CreateSelectableList(Database);
     return(View());
 }