Пример #1
0
        public ListGetResponse SearchFounders(long?tin, string lastName, string firstName, string middlName,
                                              Guid?companyId, int pageSize, int pageNumber)
        {
            ListGetResponse response = new ListGetResponse();

            FounderSerachQuery query = new FounderSerachQuery()
            {
                Tin = tin ?? null,

                LastName = (string.IsNullOrEmpty(lastName))
                ? string.Empty
                : lastName,

                FirstName = (string.IsNullOrEmpty(firstName))
                ? string.Empty
                : firstName,

                MiddleName = (string.IsNullOrEmpty(firstName))
                ? string.Empty
                : firstName,

                RelatedCompanyId = companyId ?? null,

                PageSize   = pageSize,
                PageNumber = pageNumber
            };

            foreach (Founder founder in founderService.Search(query))
            {
                response.Items.Add(entityConverter.GetListItemModel(founder));
            }

            return(response);
        }
Пример #2
0
        public IList <Founder> Search(SearchQueryBase <Founder> searchQuery)
        {
            FounderSerachQuery   query = searchQuery as FounderSerachQuery;
            IQueryable <Founder> result;

            if (query.Tin != null)
            {
                result = context
                         .GetDbSet <Founder>()
                         .Where(f => f.Tin == query.Tin.Value);
            }
            else
            {
                if (query.RelatedCompanyId != null)
                {
                    result = context
                             .GetDbSet <FounderToCompany>()
                             .Where(r => r.Company.Id == query.RelatedCompanyId.Value && !r.IsDeleted)
                             .Select(r => r.Founder)
                             .Where(f => !f.IsDeleted);
                }
                else
                {
                    result = context.Founders.Where(f => !f.IsDeleted);
                }

                if (!string.IsNullOrEmpty(query.LastName))
                {
                    result = result.Where(f => f.LastName.Contains(query.LastName));
                }

                if (!string.IsNullOrEmpty(query.FirstName))
                {
                    result = result.Where(f => f.FirstName.Contains(query.FirstName));
                }

                if (!string.IsNullOrEmpty(query.MiddleName))
                {
                    result = result.Where(f => f.MiddleName.Contains(query.MiddleName));
                }
            }

            return(result
                   .Page(searchQuery.PageNumber, searchQuery.PageSize)
                   .ToArray());
        }