Exemplo n.º 1
0
        /// <summary>
        /// The get all paged.
        /// </summary>
        /// <param name="searchPattern">
        /// The name.
        /// </param>
        /// <param name="companyId">
        /// The company Id.
        /// </param>
        /// <param name="pageIndex">
        /// The page index.
        /// </param>
        /// <param name="pageSize">
        /// The page size.
        /// </param>
        /// <param name="totalCount">
        /// The total count.
        /// </param>
        /// <returns>
        /// The <see cref="IEnumerable{T}"/>.
        /// </returns>
        public IEnumerable <Category> GetAllByCompanyAndNamePaged(string searchPattern, int companyId, int pageIndex, int pageSize, out int totalCount)
        {
            var searchIds = new List <int>();

            if (pageIndex <= default(int))
            {
                pageIndex = 1;
            }

            var queryOver = new DefaultQueryOver <Category, int>().GetQueryOver();

            if (companyId != 0)
            {
                queryOver = queryOver.Where(x => x.Company.Id == companyId);
            }

            if (!string.IsNullOrWhiteSpace(searchPattern))
            {
                searchIds = this.fullTextModel.Search(searchPattern, typeof(Category), int.MaxValue).ToList();
                queryOver = queryOver.AndRestrictionOn(x => x.Id).IsIn(searchIds);
            }

            QueryOver <Category, Category> rowCountQuery = queryOver.ToRowCountQuery();

            totalCount = this.Repository.FindOne <int>(rowCountQuery).Value;
            QueryOver <Category> pagedQuery = queryOver.OrderBy(x => x.CategoryName).Asc;

            if (pageSize > 0)
            {
                pagedQuery = pagedQuery.Take(pageSize).Skip((pageIndex - 1) * pageSize);
            }

            return(searchIds.Any() ? this.Repository.FindAll(pagedQuery).ToList().OrderBy(x => searchIds.IndexOf(x.Id)) : this.Repository.FindAll(pagedQuery));
        }
Exemplo n.º 2
0
        public static QueryOver <T> AddTake <T>(this QueryOver <T> queryOver, int?take)
        {
            if (take.HasValue && take.Value > 0)
            {
                return(queryOver.Take(take.Value));
            }

            return(queryOver);
        }
Exemplo n.º 3
0
 /// <summary>
 /// The take.
 /// </summary>
 /// <param name="q">
 /// The q.
 /// </param>
 /// <param name="maxResults">
 /// The max results.
 /// </param>
 /// <typeparam name="T">
 /// </typeparam>
 /// <typeparam name="V">
 /// </typeparam>
 /// <returns>
 /// The <see cref="QueryOver"/>.
 /// </returns>
 public static QueryOver <T, V> TakeOnly <T, V>(this QueryOver <T, V> q, int maxResults)
 {
     return((QueryOver <T, V>)q.Take(maxResults));
 }