Пример #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));
        }
Пример #2
0
        /// <summary>
        /// The get by question ids and sub module item id.
        /// </summary>
        /// <param name="smiId">
        /// The sub module item id.
        /// </param>
        /// <param name="questionsIds">
        /// The questions ids.
        /// </param>
        /// <returns>
        /// The <see cref="IEnumerable{Question}"/>.
        /// </returns>
        public IEnumerable <Question> GetByQuestionIdsAndSmiID(int smiId, List <int> questionsIds = null)
        {
            var queryOver = new DefaultQueryOver <Question, int>().GetQueryOver().Where(x => x.SubModuleItem.Id == smiId && x.IsActive == true);

            if (questionsIds != null)
            {
                queryOver = queryOver.AndRestrictionOn(x => x.Id).IsIn(questionsIds);
            }

            return(this.Repository.FindAll(queryOver));
        }
Пример #3
0
        public IEnumerable <Contact> 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 <Contact, int>().GetQueryOver();


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

            if (companyId != 0)
            {
                CompanyContact companyContact = null;
                var            queryOver2     = queryOver.JoinQueryOver(x => x.CompanyContacts, () => companyContact).Where(() => companyContact.Company.Id == companyId);
                var            rowCountQuery  = queryOver2.ToRowCountQuery();
                totalCount = this.Repository.FindOne <int>(rowCountQuery).Value;

                if (pageSize > 0)
                {
                    var pagedQueryOver = queryOver2.Take(pageSize).Skip((pageIndex - 1) * pageSize);
                    return(searchIds.Any() ? this.Repository.FindAll(pagedQueryOver).ToList().OrderBy(x => searchIds.IndexOf(x.Id)) : this.Repository.FindAll(pagedQueryOver));
                }

                return(searchIds.Any() ? this.Repository.FindAll(queryOver2).ToList().OrderBy(x => searchIds.IndexOf(x.Id)) : this.Repository.FindAll(queryOver2));
            }
            else
            {
                var rowCountQuery = queryOver.ToRowCountQuery();
                totalCount = this.Repository.FindOne <int>(rowCountQuery).Value;

                if (pageSize > 0)
                {
                    var pagedQueryOver = queryOver.Take(pageSize).Skip((pageIndex - 1) * pageSize);
                    return(searchIds.Any() ? this.Repository.FindAll(pagedQueryOver).ToList().OrderBy(x => searchIds.IndexOf(x.Id)) : this.Repository.FindAll(pagedQueryOver));
                }

                return(searchIds.Any() ? this.Repository.FindAll(queryOver).ToList().OrderBy(x => searchIds.IndexOf(x.Id)) : this.Repository.FindAll(queryOver));
            }
        }