public IEnumerable <string> ListFunctionsForRoles(IEnumerable <string> roles, IUnitOfWork unitOfWork = null) { // Get local copy of reference to roles dictionary Dictionary <string, Role> rolesByName = _rolesByName; // If reference does not exist, create the dictionary if (rolesByName == null) { IEnumerable <Role> rolesObjects = _authorizationRepository.ListRoles(unitOfWork); rolesByName = rolesObjects.GroupBy(r => r.Name).ToDictionary(g => g.Key, g => g.First()); _rolesByName = rolesByName; } // Get long list of all functions in roles List <string> functions = new List <string>(); foreach (string role in roles) { Role roleObject = rolesByName[role]; functions.AddRange(roleObject.Functions.Select(f => f.Name)); } // Return list of functions with no duplicates return(functions.Distinct()); }