Пример #1
0
        /// <summary>
        ///     GetSortedFieldFilterResult
        /// </summary>
        /// <param name="searchField"></param>
        /// <param name="criteria"></param>
        /// <param name="sortDirection"></param>
        /// <returns></returns>
        public virtual PagedListResult <TEntity> GetSortedFieldFilterResult(string searchField = null,
                                                                            string criteria    = null, SortDirection sortDirection = SortDirection.Ascending)
        {
            var repository = new SearchRepository <TEntity>();

            searchField = !string.IsNullOrEmpty(searchField) ? searchField : "Id";
            //TODO: once UpdatedOn is implemented - this will be default
            criteria = !string.IsNullOrEmpty(criteria) ? criteria : "";

            var q = new SearchQuery <TEntity>();

            if (!string.IsNullOrEmpty(searchField))
            {
                q.AddSortCriteria(
                    new FieldSortCriteria <TEntity>(searchField, sortDirection));
            }

            if (!string.IsNullOrEmpty(criteria))
            {
                q.AddSortCriteria(
                    new FieldSortCriteria <TEntity>(criteria, sortDirection));
            }

            var result = repository.Search(q);

            return(result);
        }
Пример #2
0
        /// <summary>
        ///     PersonFieldSortCriteriaTest
        /// </summary>
        /// <param name="searchField"></param>
        /// <param name="criteria"></param>
        public static void PersonFieldSortCriteriaTest(string searchField = "Bob", string criteria = "S")
        {
            var repository = new SearchRepository <Person>();

            searchField = !string.IsNullOrEmpty(searchField) ? searchField : "Bob";
            criteria    = !string.IsNullOrEmpty(criteria) ? criteria : "S";

            var q = new SearchQuery <Person>();

            if (!string.IsNullOrEmpty(searchField))
            {
                q.AddSortCriteria(
                    new FieldSortCriteria <Person>(searchField, SortDirection.Ascending));
            }

            if (!string.IsNullOrEmpty(criteria))
            {
                q.AddSortCriteria(
                    new FieldSortCriteria <Person>(criteria, SortDirection.Ascending));
            }

            var result = repository.Search(q);

            foreach (var entity in result.Entities)
            {
                Audit.Log.Debug(searchField + "=" + entity.FirstName + ";" +
                                criteria + "=" + entity.LastName);
            }
        }