private IActionResult Search(ProductSearchQueryModel viewParams)
        {
            ProductManagement pm = new ProductManagement();
            var productList      = pm.Search(viewParams.Code, viewParams.Name,
                                             null, null, viewParams.IsActive, viewParams.Page * 10, 10);

            ProductViewModel model = new ProductViewModel()
            {
                Products = productList,
                Filter   = viewParams
            };

            return(View("Search", model));
        }
Example #2
0
        public IHttpActionResult Get([FromUri] ProductSearchQueryModel queryModel)
        {
            if (!ModelState.IsValid)
            {
                return(this.Error().InvalidParameters("One or more of the required query parameters are missing."));
            }
            if (queryModel == null)
            {
                queryModel = new ProductSearchQueryModel();
            }
            var products = _repository.Search(queryModel, _clock.GetCurrentInstant().ToDateTimeUtc());

            var searchModel = new SearchResultModel <ProductNameModel>()
            {
                Items      = products.Items.ToList(),
                TotalCount = products.TotalCount
            };

            return(Ok(searchModel));
        }
Example #3
0
        public PagedQueryResult <ProductNameModel> Search(ProductSearchQueryModel searchQuery, DateTime onDate)
        {
            lock (_session)
            {
                var where = new List <Expression <Func <Product_BySearch.IndexedFields, bool> > >();
                if (!string.IsNullOrWhiteSpace(searchQuery.Externalidentifier))
                {
                    where.Add(p => p.Externalidentifier.Equals(searchQuery.Externalidentifier, StringComparison.OrdinalIgnoreCase));
                }

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

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

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

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

                if (!string.IsNullOrWhiteSpace(searchQuery.NameOrRef))
                {
                    var termsList = searchQuery.NameOrRef.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                    where.AddRange(termsList.Select(
                                       term => (Expression <Func <Product_BySearch.IndexedFields, bool> >)(p => p.TokenizedName
                                                                                                           .StartsWith(term))));
                }
                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 = DocumentSessionExtensions
                            .GetAll <Product_BySearch.IndexedFields, Product_BySearch, ProductTransformer_BySearch, ProductNameModel>(_session,
                                                                                                                                      where.Any() ? where.AggregateAnd() : null,
                                                                                                                                      out int totalResult, sortBy, searchQuery.OrderByDirection?.ToString() ?? "asc",
                                                                                                                                      searchQuery.Skip,
                                                                                                                                      searchQuery.Top);

                var totalCount = searchQuery.IncludeTotalCount ? totalResult : 0;

                return(new PagedQueryResult <ProductNameModel>(totalCount, items));
            }
        }
 public PagedQueryResult <ProductNameModel> Search(ProductSearchQueryModel searchQuery, DateTime onDate)
 {
     throw new NotImplementedException();
 }
Example #5
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()));
        }