public JsonResult GetUsersRoleJson(String roleName) { AuthenticationsAndAuthorizationsOperations anaOps = new AuthenticationsAndAuthorizationsOperations(); List <ListUsersViewModel> usersInRoleList = new List <ListUsersViewModel>(); List <ListUsersViewModel> usersNOTInRoleList = new List <ListUsersViewModel>(); if (!String.IsNullOrEmpty(roleName) && Roles.RoleExists(roleName)) { String[] inRoleUsers = Roles.GetUsersInRole(roleName); MembershipUserCollection allUsers = Membership.GetAllUsers(); foreach (MembershipUser user in allUsers) { ListUsersViewModel listUsersViewModel = new ListUsersViewModel(); if (inRoleUsers.Contains(user.UserName)) { listUsersViewModel.Email = user.Email; listUsersViewModel.ExpiredDate = (anaOps.GetExpiryDate(user.UserName)).ToString(dateTimeFormat); listUsersViewModel.LastActivityDate = (user.LastActivityDate).ToString(dateTimeFormat); listUsersViewModel.MobileAlias = anaOps.GetMobileAliasByUserName(user.UserName); listUsersViewModel.UserName = user.UserName; listUsersViewModel.ThisRoleOwner = anaOps.IsRoleOwner(user.UserName, roleName); usersInRoleList.Add(listUsersViewModel); } if (!inRoleUsers.Contains(user.UserName)) { listUsersViewModel.Email = user.Email; listUsersViewModel.ExpiredDate = (anaOps.GetExpiryDate(user.UserName)).ToString(dateTimeFormat); listUsersViewModel.LastActivityDate = (user.LastActivityDate).ToString(dateTimeFormat); listUsersViewModel.MobileAlias = anaOps.GetMobileAliasByUserName(user.UserName); listUsersViewModel.UserName = user.UserName; usersNOTInRoleList.Add(listUsersViewModel); } } } return(Json(new { TotalInRole = usersInRoleList.Count, DataInRole = usersInRoleList, TotalNotInRole = usersNOTInRoleList.Count, DataNotInRole = usersNOTInRoleList })); }