Beispiel #1
0
        /// <summary>
        /// The get all by company id. and contact
        /// </summary>
        /// <param name="companyIds">
        /// The company Ids.
        /// </param>
        /// <param name="contact">
        /// The contact.
        /// </param>
        /// <returns>
        /// The <see cref="IEnumerable{Category}"/>.
        /// </returns>
        public IEnumerable <Category> GetAllByCompanyIdsAndContact(List <int> companyIds, Contact contact)
        {
            var query = new DefaultQueryOver <Category, int>().GetQueryOver().WhereRestrictionOn(x => x.Company.Id).IsIn(companyIds);

            if (!contact.IsSuperAdmin && contact.CompanyContacts.ToList().Any(x => x.ContactType.Id == (int)ContactTypeEnum.Contact && companyIds.Contains(x.Company.Id)))
            {
                Contact c         = null;
                var     contactId = contact.Id;
                var     resQuery  = query.JoinQueryOver(x => x.Contacts, () => c).Where(() => c.Id == contactId);
                return(this.Repository.FindAll(resQuery).ToList());
            }

            return(this.Repository.FindAll(query).ToList());
        }
Beispiel #2
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));
            }
        }