Beispiel #1
0
        /// <summary>
        /// Searches user accounts by resolved names limited to the specified number of records.
        /// </summary>
        /// <param name="searchText">Search text to lookup.</param>
        /// <param name="limit">Limit of number of record to return.</param>
        /// <returns>Search results as "IDLabel" instances - serialized as JSON [{ id : "value", label : "name" }, ...]; useful for dynamic lookup lists.</returns>
        public IEnumerable <IDLabel> SearchUserAccounts(string searchText, int limit)
        {
            if (limit < 1)
            {
                return(DataContext
                       .Table <UserAccount>()
                       .QueryRecords()
                       .Select(record =>
                {
                    record.Name = UserInfo.SIDToAccountName(record.Name ?? "");
                    return record;
                })
                       .Where(record => record.Name?.StartsWith(searchText, StringComparison.InvariantCultureIgnoreCase) ?? false)
                       .Select(record => IDLabel.Create(record.ID.ToString(), record.Name)));
            }

            return(DataContext
                   .Table <UserAccount>()
                   .QueryRecords()
                   .Select(record =>
            {
                record.Name = UserInfo.SIDToAccountName(record.Name ?? "");
                return record;
            })
                   .Where(record => record.Name?.StartsWith(searchText, StringComparison.InvariantCultureIgnoreCase) ?? false)
                   .Take(limit)
                   .Select(record => IDLabel.Create(record.ID.ToString(), record.Name)));
        }
        /// <summary>
        /// Gets the users for a specific role filtered using primeui autocomplete
        /// </summary>
        /// <param name="role">Role that you want users from</param>
        /// <param name="searchText">primeui search text</param>
        /// <param name="limit">number of users to return, -1 is default and returns all</param>
        /// <returns>IENumerable of ID Labels used with primeui autocomplete</returns>

        public IEnumerable <IDLabel> SearchUsers(string role, string searchText, int limit = -1)
        {
            RecordRestriction restriction = new RecordRestriction("ID IN (SELECT UserAccountID FROM ApplicationRoleUserAccount WHERE ApplicationRoleUserAccount.ApplicationRoleID IN (SELECT ID FROM ApplicationRole WHERE Name = {0}))", role);

            if (limit < 1)
            {
                return(DataContext
                       .Table <UserAccount>()
                       .QueryRecords(restriction: restriction)
                       .Select(record =>
                {
                    record.Name = UserInfo.SIDToAccountName(record.Name ?? "");
                    return record;
                })
                       .Where(record => record.Name?.ToLower().Contains(searchText.ToLower()) ?? false)
                       .Select(record => IDLabel.Create(record.ID.ToString(), record.Name)));
            }

            return(DataContext
                   .Table <UserAccount>()
                   .QueryRecords(restriction: restriction)
                   .Select(record =>
            {
                record.Name = UserInfo.SIDToAccountName(record.Name ?? "");
                return record;
            })
                   .Where(record => record.Name?.ToLower().Contains(searchText.ToLower()) ?? false)
                   .Take(limit)
                   .Select(record => IDLabel.Create(record.ID.ToString(), record.Name)));
        }