コード例 #1
0
        public IHttpActionResult Get([FromUri] RestrictionSearchQueryModel searchQuery)
        {
            if (!ModelState.IsValid)
            {
                return(this.Error().InvalidParameters());
            }

            if (searchQuery == null)
            {
                searchQuery = new RestrictionSearchQueryModel();
            }

            searchQuery.DateRangeEnd   = searchQuery.DateRangeEnd?.ToUniversalTime();
            searchQuery.DateRangeStart = searchQuery.DateRangeStart?.ToUniversalTime();

            var restrictions = _restrictionRepository.Get(searchQuery);

            var searchModel = new SearchResultModel <RestrictionWithDescModel>
            {
                Items = restrictions?.Items != null && restrictions.Items.Any()
                    ? _mapper.Map <List <RestrictionWithDescModel> >(restrictions.Items) : null,
                TotalCount = restrictions?.TotalCount ?? 0
            };

            return(Ok(searchModel));
        }
コード例 #2
0
        protected CallMethodResult SearchRestrictions(
            List <string> salesAreaNames,
            DateTime?startDate,
            DateTime?endDate,
            RestrictionType?restrictionType,
            bool matchAllSpecifiedSalesAreas)
        {
            var queryModel = new RestrictionSearchQueryModel
            {
                SalesAreaNames              = salesAreaNames,
                DateRangeStart              = startDate,
                DateRangeEnd                = endDate,
                RestrictionType             = restrictionType,
                MatchAllSpecifiedSalesAreas = matchAllSpecifiedSalesAreas
            };
            var res = Repository.Get(queryModel);

            TestContext.LastOperationCount   = res?.Items?.Count ?? 0;
            TestContext.LastCollectionResult = res?.Items;
            TestContext.LastSingleResult     = null;

            return(CallMethodResult.CreateHandled());
        }
コード例 #3
0
        public PagedQueryResult <Tuple <Restriction, RestrictionDescription> > Get(RestrictionSearchQueryModel query)
        {
            lock (_session)
            {
                var restrictions = _session.GetAll <Restriction>();
                if (query.SalesAreaNames != null && query.SalesAreaNames.Any())
                {
                    if (query.MatchAllSpecifiedSalesAreas) // Restrictions that relate to all specified sales areas
                    {
                        restrictions = restrictions?.Where(p => (p.SalesAreas == null) || (!p.SalesAreas.Any()) ||
                                                           (p.SalesAreas.Intersect(query.SalesAreaNames).Count() ==
                                                            query.SalesAreaNames.Count))?.ToList();
                    }
                    else // Restrictions that relate to any of the specified sales areas
                    {
                        restrictions = restrictions?.Where(p => (p.SalesAreas == null) || (!p.SalesAreas.Any()) ||
                                                           (p.SalesAreas.Intersect(query.SalesAreaNames).Any()))
                                       ?.ToList();
                    }
                }
                if (query.DateRangeStart != null && query.DateRangeEnd != null)
                {
                    restrictions = restrictions?.Where(c => (c.StartDate.Date >= query.DateRangeStart.Value.Date &&
                                                             c.StartDate.Date < query.DateRangeEnd.Value.Date
                                                             .AddDays(1)) ||
                                                       (c.EndDate != null && c.EndDate.Value.Date >=
                                                        query.DateRangeStart.Value.Date &&
                                                        c.EndDate.Value.Date < query.DateRangeEnd.Value.Date
                                                        .AddDays(1)) ||
                                                       (c.StartDate.Date < query.DateRangeEnd.Value.Date
                                                        .AddDays(1) &&
                                                        (c.EndDate == null || c.EndDate.Value.Date >=
                                                         query.DateRangeEnd.Value.Date))).ToList();
                }
                else
                {
                    if (query.DateRangeStart != null && query.DateRangeEnd == null)
                    {
                        restrictions = restrictions?.Where(c => (c.StartDate.Date >= query.DateRangeStart.Value.Date) ||
                                                           (c.StartDate.Date < query.DateRangeStart.Value.Date
                                                            .AddDays(1) &&
                                                            (c.EndDate == null ||
                                                             c.EndDate.Value.Date >= query.DateRangeStart.Value
                                                             .Date))).ToList();
                    }
                    else
                    {
                        if (query.DateRangeStart == null && query.DateRangeEnd != null)
                        {
                            restrictions = restrictions?
                                           .Where(c => (c.EndDate != null &&
                                                        c.EndDate.Value.Date < query.DateRangeEnd.Value.Date.AddDays(1)) ||
                                                  (c.StartDate.Date < query.DateRangeEnd.Value.Date.AddDays(1) &&
                                                   (c.EndDate == null ||
                                                    c.EndDate.Value.Date >= query.DateRangeEnd.Value.Date)))
                                           .ToList();
                        }
                    }
                }

                if (query.RestrictionType != null)
                {
                    restrictions = restrictions?.Where(p => p.RestrictionType == query.RestrictionType)?.ToList();
                }

                if (restrictions == null || !restrictions.Any())
                {
                    return(new PagedQueryResult <Tuple <Restriction, RestrictionDescription> >(0, null));
                }

                var sortedItems = restrictions.Sort(query.OrderBy.ToString(), query.OrderDirection.ToString().ToLower())
                                  ?.ToList();

                if (query.Skip != null)
                {
                    sortedItems = sortedItems?.Skip(query.Skip.Value).ToList();
                }

                if (query.Top != null)
                {
                    sortedItems = sortedItems?.Take(query.Top.Value).ToList();
                }

                if (sortedItems == null || !sortedItems.Any())
                {
                    return(new PagedQueryResult <Tuple <Restriction, RestrictionDescription> >(0, null));
                }

                List <ProgrammeNameModel> programmes = null;
                List <Product>            products   = null;
                List <Clash> clashes          = null;
                var          externalProgRefs = sortedItems.Where(i => !string.IsNullOrWhiteSpace(i?.ExternalProgRef))
                                                .Select(i => i.ExternalProgRef)
                                                .Distinct(StringComparer.OrdinalIgnoreCase)?.ToList();
                if (externalProgRefs.Any())
                {
                    programmes = DocumentSessionExtensions
                                 .GetAll <Programmes_ByIdAndSalesAreaStartDateTime.IndexedFields,
                                          Programmes_ByIdAndSalesAreaStartDateTime,
                                          ProgrammeTransformer_BySearch, ProgrammeNameModel>(_session,
                                                                                             p => p.ExternalReference.In(externalProgRefs),
                                                                                             out int totalResult, null, null);
                }
                var productCodes = sortedItems.Where(i => i.ProductCode != 0).Select(i => i.ProductCode.ToString())
                                   .Distinct(StringComparer.OrdinalIgnoreCase).ToList();

                if (productCodes.Any())
                {
                    products = _session.GetAll <Product>(p => p.Externalidentifier.In(productCodes),
                                                         indexName: Product_BySearch.DefaultIndexName, isMapReduce: false);
                }
                var clashCodes = sortedItems.Where(i => !string.IsNullOrWhiteSpace(i?.ClashCode))
                                 .Select(i => i.ClashCode.ToString())
                                 .Distinct(StringComparer.OrdinalIgnoreCase).ToList();

                if (clashCodes.Any())
                {
                    clashes = _session.GetAll <Clash>(p => p.Externalref.In(clashCodes),
                                                      indexName: Clash_BySearch.DefaultIndexName, isMapReduce: false);
                }
                var items = (from res in sortedItems
                             let programme = !string.IsNullOrWhiteSpace(res.ExternalProgRef)
                        ? programmes.EmptyIfNull()
                                             .FirstOrDefault(p => p.ExternalReference.Equals(res.ExternalProgRef,
                                                                                             StringComparison.OrdinalIgnoreCase))
                        : null
                                             let product = res.ProductCode != 0
                                 ? products.EmptyIfNull()
                                                           .FirstOrDefault(p => p.Externalidentifier.Equals(res.ProductCode.ToString(),
                                                                                                            StringComparison.OrdinalIgnoreCase))
                                 : null
                                                           let clash = !string.IsNullOrWhiteSpace(res.ClashCode)
                                 ? clashes.EmptyIfNull()
                                                                       .FirstOrDefault(
                                 c => c.Externalref.Equals(res.ClashCode, StringComparison.OrdinalIgnoreCase))
                                 : null

                                                                       select Tuple.Create(res, new RestrictionDescription()
                {
                    ClashDescription = clash?.Description,
                    ProductDescription = product?.Name,
                    ProgrammeDescription = programme?.ProgrammeName
                })).ToList();
                return(new PagedQueryResult <Tuple <Restriction, RestrictionDescription> >(restrictions.Count, items));
            }
        }
コード例 #4
0
 public PagedQueryResult <Tuple <Restriction, RestrictionDescription> > Get(RestrictionSearchQueryModel query)
 {
     throw new NotImplementedException();
 }