public List <UserViewModel> GetSortedUsers(string role) { //Instance of the ManageRoles class to get the user's role ManageRoles man = new ManageRoles(); //List of view models to return List <UserViewModel> viewModel = new List <UserViewModel>(); //A list of all the users in the database List <ApplicationUser> users = _db.Users.ToList(); //Get all the users from the list with the right role and adding them to te view model foreach (var tmp in users) { if (man.UserIsInRole(tmp.Id, role)) { viewModel.Add(new UserViewModel() { Id = tmp.Id, FullName = tmp.FullName, SSN = tmp.SSN, Email = tmp.Email, UserRole = man.GetUserRole(tmp.Email) }); } ; } //Return the view model return(viewModel); }