Пример #1
0
        public PagedQueryResult <ProgrammeNameModel> Search(ProgrammeSearchQueryModel searchQuery)
        {
            if (searchQuery == null)
            {
                throw new ArgumentNullException(nameof(searchQuery));
            }

            var query = _dbContext.Query <Entities.Tenant.Programmes.Programme>();

            if (searchQuery.SalesArea != null && searchQuery.SalesArea.Any())
            {
                query = query.Where(e => searchQuery.SalesArea.Contains(e.SalesArea.Name));
            }

            if (searchQuery.FromDateInclusive != default)
            {
                query = query.Where(p => p.StartDateTime >= searchQuery.FromDateInclusive);
            }

            if (searchQuery.ToDateInclusive != default)
            {
                query = query.Where(p => p.StartDateTime <= searchQuery.ToDateInclusive);
            }

            if (!string.IsNullOrWhiteSpace(searchQuery.NameOrRef))
            {
                var searchCondition = _searchConditionBuilder
                                      .StartAllWith(searchQuery.NameOrRef.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries))
                                      .Build();

                query = query
                        .Where(p => EF.Functions.Contains(
                                   EF.Property <string>(p.ProgrammeDictionary, Entities.Tenant.ProgrammeDictionary.SearchField), searchCondition));
            }

            if (searchQuery.OrderBy != null)
            {
                var sortBy = searchQuery.OrderBy == ProgrammeOrder.LocalDate
                    ? nameof(Programme.StartDateTime)
                    : searchQuery.OrderBy.ToString();

                query = query.OrderBySingleItem(sortBy,
                                                searchQuery.OrderByDirection ?? OrderDirection.Asc);
            }

            var pQuery = query.Select(x => new ProgrammeNameModel
            {
                ExternalReference = x.ProgrammeDictionary.ExternalReference,
                ProgrammeName     = x.ProgrammeDictionary.Name
            }).Distinct();

            return(new PagedQueryResult <ProgrammeNameModel>(pQuery.Count(),
                                                             pQuery.ApplyPaging(searchQuery.Skip, searchQuery.Top).ToList()));
        }
Пример #2
0
        public PagedQueryResult <ClashNameModel> Search(ClashSearchQueryModel queryModel)
        {
            if (queryModel == null)
            {
                throw new ArgumentNullException(nameof(queryModel));
            }

            var query = _dbContext.Query <Entities.Tenant.Clash>();

            if (!string.IsNullOrWhiteSpace(queryModel.NameOrRef))
            {
                var searchCondition = _searchConditionBuilder.StartAllWith(queryModel.NameOrRef.Split(new[] { " " },
                                                                                                      StringSplitOptions.RemoveEmptyEntries)).Build();
                query = query.Where(p =>
                                    EF.Functions.Contains(EF.Property <string>(p, Entities.Tenant.Clash.SearchField), searchCondition));
            }

            return(new PagedQueryResult <ClashNameModel>(query.Count(),
                                                         query.ApplyPaging(queryModel.Skip, queryModel.Top).ProjectTo <ClashNameModel>(_mapper.ConfigurationProvider).ToList()));
        }
Пример #3
0
        public PagedQueryResult <ProductNameModel> Search(ProductSearchQueryModel searchQuery, DateTime onDate)
        {
            var where = new List <Expression <Func <Entities.Tenant.Products.Product, bool> > >();

            if (!string.IsNullOrWhiteSpace(searchQuery.Externalidentifier))
            {
                where.Add(p => p.Externalidentifier == searchQuery.Externalidentifier);
            }

            if (!string.IsNullOrWhiteSpace(searchQuery.Name))
            {
                where.Add(p => p.Name == searchQuery.Name);
            }

            if (!string.IsNullOrWhiteSpace(searchQuery.ClashCode))
            {
                where.Add(p => p.ClashCode == searchQuery.ClashCode);
            }

            if (searchQuery.FromDateInclusive != default)
            {
                where.Add(p => p.EffectiveStartDate >= searchQuery.FromDateInclusive);
            }

            if (searchQuery.ToDateInclusive != default)
            {
                where.Add(p => p.EffectiveEndDate < searchQuery.ToDateInclusive.AddTicks(1));
            }

            if (!string.IsNullOrWhiteSpace(searchQuery.NameOrRef))
            {
                var query = _searchConditionBuilder.StartAllWith(
                    searchQuery.NameOrRef.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries)).Build();
                where.Add(p => EF.Functions.Contains(EF.Property <string>(p, Entities.Tenant.Products.Product.SearchFieldName), query));
            }

            string sortBy;

            switch (searchQuery.OrderBy)
            {
            case ProductOrder.StartDate:
                sortBy = "EffectiveStartDate";
                break;

            case ProductOrder.EndDate:
                sortBy = "EffectiveEndDate";
                break;

            case null:
                sortBy = null;
                break;

            default:
                sortBy = searchQuery.OrderBy.ToString();
                break;
            }

            var items = !where.Any()
                ? ActualProductQuery(onDate)
                : ActualProductQuery(onDate, where.AggregateAnd());

            var sortedItems = items.OrderBySingleItem(sortBy,
                                                      searchQuery.OrderByDirection ?? Domain.Generic.OrderDirection.Asc)
                              .ApplyPaging(searchQuery.Skip, searchQuery.Top);

            var totalCount = searchQuery.IncludeTotalCount ? items.Count() : 0;

            return(new PagedQueryResult <ProductNameModel>(totalCount, sortedItems.ProjectTo <ProductNameModel>(_mapper.ConfigurationProvider).ToList()));
        }