public async Task <IActionResult> EditRol(string id)
        {
            // Search for Rol Id
            var rol = await processRoles.FindByIdAsync(id);

            if (rol == null)
            {
                ViewBag.ErrorMessage = $"Rol with Id = {id} was not found";
            }

            var model = new EditRolViewModel
            {
                Id      = rol.Id,
                NameRol = rol.Name
            };

            //Get all users
            foreach (var user in processUsers.Users)
            {
                if (await processUsers.IsInRoleAsync(user, rol.Name))
                {
                    model.Users.Add(user.UserName);
                }
            }

            return(View(model));
        }
Beispiel #2
0
        public async Task <IActionResult> EditarRol(EditRolViewModel model)
        {
            var role = await _roleManager.FindByIdAsync(model.Id);

            if (role == null)
            {
                Alert("Este rol no se encuentra en el sistema", NotificationType.error);
                return(RedirectToAction("roles", "admin"));
            }
            else
            {
                role.Name = model.RoleName;
                var result = await _roleManager.UpdateAsync(role);

                if (result.Succeeded)
                {
                    return(RedirectToAction("Roles"));
                }

                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError("", error.Description);
                }
            }

            return(View(model));
        }
        public async Task <IActionResult> EditRol(EditRolViewModel model)
        {
            // Search for Rol Id
            var rol = await processRoles.FindByIdAsync(model.Id);

            if (rol == null)
            {
                ViewBag.ErrorMessage = $"Rol with Id = {model.Id} was not found";
                return(View("Error"));
            }
            else
            {
                rol.Name = model.NameRol;
                var result = await processRoles.UpdateAsync(rol);

                if (result.Succeeded)
                {
                    return(RedirectToAction("ListRoles"));
                }

                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError("", error.Description);
                }

                return(View(model));
            }
        }
Beispiel #4
0
        public async Task <IActionResult> EditarRol(string id)
        {
            var role = await _roleManager.FindByIdAsync(id);

            if (role == null)
            {
                Alert("Este rol no se encuentra en el sistema", NotificationType.error);
                return(RedirectToAction("roles", "admin"));
            }

            var model = new EditRolViewModel
            {
                Id       = role.Id,
                RoleName = role.Name
            };

            foreach (var user in _userManager.Users)
            {
                if (await _userManager.IsInRoleAsync(user, role.Name))
                {
                    model.Users.Add(user.Identification);
                }
            }

            return(View(model));
        }