public IActionResult AssignUser(int id)
        {
            ViewBag.ticketId = id;

            var ticket = dbContext.Tickets.Where(t => t.Id == id).Include(t => t.TicketApplicationUsers).FirstOrDefault();

            if (ticket == null)
            {
                return(NotFound());
            }

            var model = new List <EditUsersInRoleViewModel>();
            var users = userManager.Users.ToList();

            foreach (var user in users)
            {
                var EditUsersInRoleViewModel = new EditUsersInRoleViewModel
                {
                    UserId   = user.Id,
                    UserName = user.UserName
                };

                EditUsersInRoleViewModel.IsSelected = ticket.TicketApplicationUsers.Any(tau => tau.ApplicationUser == user) ? true : false;

                model.Add(EditUsersInRoleViewModel);
            }
            return(View(model));
        }
예제 #2
0
        public async Task <IActionResult> EditUsersInRole(string id)
        {
            ViewBag.roleId = id;

            var role = await _roleManager.FindByIdAsync(id);

            if (role == null)
            {
                return(NotFound());
            }

            var model = new List <EditUsersInRoleViewModel>();
            var users = _userManager.Users.ToList();

            foreach (var user in users)
            {
                var EditUsersInRoleViewModel = new EditUsersInRoleViewModel
                {
                    UserId   = user.Id,
                    UserName = user.UserName
                };

                EditUsersInRoleViewModel.IsSelected = await _userManager.IsInRoleAsync(user, role.Name) ? true : false;

                model.Add(EditUsersInRoleViewModel);
            }
            return(View(model));
        }