public async Task Test_Search_Products_By_Criteria()
        {
            var filteringOptions = new List <FilteringOption>()
            {
                new FilteringOption()
                {
                    Field = "name", Operator = FilteringOption.FilteringOperator.Contains, Value = "Camera"
                }
            };
            var sortingOption = new List <SortingOption>()
            {
                new SortingOption()
                {
                    Field = "name", Direction = SortingOption.SortingDirection.ASC, Priority = 1
                }
            };
            var pageSearchArgs = new Core.Pagination.SearchArgs()
            {
                FilteringOptions = filteringOptions, PagingStrategy = PagingStrategy.WithCount, SortingOptions = sortingOption, PageIndex = 1, PageSize = 10
            };
            var searchPageRequest = new PageSearchArgs()
            {
                Args = pageSearchArgs
            };

            var provider     = ClaimsProviderTest.WithAdminClaims();
            var client       = Factory.CreateClientWithTokenAuth(provider);
            var httpResponse = await client.PostAsync("/api/product/search", new StringContent(JsonConvert.SerializeObject(searchPageRequest), Encoding.UTF8, "application/json"));

            httpResponse.EnsureSuccessStatusCode();
            var stringResponse = await httpResponse.Content.ReadAsStringAsync();

            Assert.Equal(HttpStatusCode.OK, httpResponse.StatusCode);
        }
예제 #2
0
        public async Task <IPagedList <Comment> > GetComments(PageSearchArgs args)
        {
            var itemsPagedList = await _feedRepository.GetCommentsAsync(args);

            var result = new PagedList <Comment>(
                itemsPagedList.PageIndex,
                itemsPagedList.PageSize,
                itemsPagedList.TotalCount,
                itemsPagedList.TotalPages,
                itemsPagedList.Items);

            return(result);
        }
예제 #3
0
        public async Task <IPagedList <MainFeed> > GetFeeds(PageSearchArgs args, Guid?userId)
        {
            var itemsPagedList = await _feedRepository.GetFeedsAsync(args, userId);

            var result = new PagedList <MainFeed>(
                itemsPagedList.PageIndex,
                itemsPagedList.PageSize,
                itemsPagedList.TotalCount,
                itemsPagedList.TotalPages,
                itemsPagedList.Items);

            return(result);
        }
예제 #4
0
        public async Task <IPagedList <CategoryModel> > SearchCategories(PageSearchArgs args)
        {
            var categoryPagedList = await _categoryRepository.SearchCategoriesAsync(args);

            var categoryModels = ObjectMapper.Mapper.Map <List <CategoryModel> >(categoryPagedList.Items);

            var categoryModelPagedList = new PagedList <CategoryModel>(
                categoryPagedList.PageIndex,
                categoryPagedList.PageSize,
                categoryPagedList.TotalCount,
                categoryPagedList.TotalPages,
                categoryModels);

            return(categoryModelPagedList);
        }
        public async Task <IPagedList <CoffeeFortuneTelling> > GetFortuneTellerItems(PageSearchArgs args, Guid userId)
        {
            var itemsPagedList = await _coffeeFortuneTellingRepository.GetFortuneTellerItemsAsync(args, userId);

            //var categoryModels = ObjectMapper.Mapper.Map<List<CategoryModel>>(categoryPagedList.Items);

            var result = new PagedList <CoffeeFortuneTelling>(
                itemsPagedList.PageIndex,
                itemsPagedList.PageSize,
                itemsPagedList.TotalCount,
                itemsPagedList.TotalPages,
                itemsPagedList.Items);

            return(result);
        }
        public async Task <IPagedList <ProductModel> > SearchProducts(PageSearchArgs args)
        {
            var productPagedList = await _productRepository.SearchProductsAsync(args);

            //TODO: PagedList<TSource> will be mapped to PagedList<TDestination>;
            var productModels = ObjectMapper.Mapper.Map <List <ProductModel> >(productPagedList.Items);

            var productModelPagedList = new PagedList <ProductModel>(
                productPagedList.PageIndex,
                productPagedList.PageSize,
                productPagedList.TotalCount,
                productPagedList.TotalPages,
                productModels);

            return(productModelPagedList);
        }
예제 #7
0
        public Task <IPagedList <Comment> > GetCommentsAsync(PageSearchArgs args)
        {
            if (args == null || args.FilteringOptions == null || !args.FilteringOptions.Any(a => a.Field == "RefId"))
            {
                throw new BusinessException("MissingFilter", "RefId eksik.");
            }

            IQueryable <Comment> query = _context.Comments.Include(a => a.User);

            var orderByList = new List <Tuple <SortingOption, Expression <Func <Comment, object> > > >();

            if (orderByList.Count == 0)
            {
                orderByList.Add(new Tuple <SortingOption, Expression <Func <Comment, object> > >(new SortingOption {
                    Direction = SortingOption.SortingDirection.DESC
                }, c => c.CreateDate));
            }

            var filterList = new List <Tuple <FilteringOption, Expression <Func <Comment, bool> > > >();

            if (args.FilteringOptions != null)
            {
                foreach (var filteringOption in args.FilteringOptions)
                {
                    switch (filteringOption.Field)
                    {
                    case "RefId":
                        filterList.Add(new Tuple <FilteringOption, Expression <Func <Comment, bool> > >(filteringOption, c => c.RefId == Guid.Parse(filteringOption.Value.ToString())));
                        break;
                    }
                }
            }

            var pagedList = new PagedList <Comment>(query, new PagingArgs {
                PageIndex = args.PageIndex, PageSize = args.PageSize, PagingStrategy = args.PagingStrategy
            }, orderByList, filterList);

            return(Task.FromResult <IPagedList <Comment> >(pagedList));
        }
예제 #8
0
        public Task <IPagedList <MainFeed> > GetFeedsAsync(PageSearchArgs args, Guid?userId)
        {
            IQueryable <MainFeed> query = _context.MainFeeds.Where(a => a.Status == MainFeedStatus.Active);

            var orderByList = new List <Tuple <SortingOption, Expression <Func <MainFeed, object> > > >();

            if (orderByList.Count == 0)
            {
                orderByList.Add(new Tuple <SortingOption, Expression <Func <MainFeed, object> > >(new SortingOption {
                    Direction = SortingOption.SortingDirection.DESC
                }, c => c.PublishedDateUtc));
            }

            var pagedList = new PagedList <MainFeed>(query, new PagingArgs {
                PageIndex = args.PageIndex, PageSize = args.PageSize, PagingStrategy = args.PagingStrategy
            }, orderByList, null);

            if (userId.HasValue)
            {
                FillFeedUserLikedTyes(pagedList.Items, userId.Value);
            }

            return(Task.FromResult <IPagedList <MainFeed> >(pagedList));
        }
예제 #9
0
 public SearchArticlesCommand(PageSearchArgs searchParams)
 {
     SearchParams = searchParams;
 }
        public Task <IPagedList <Product> > SearchProductsAsync(PageSearchArgs args)
        {
            var query = Table.Include(p => p.Category);

            var orderByList = new List <Tuple <SortingOption, Expression <Func <Product, object> > > >();

            if (args.SortingOptions != null)
            {
                foreach (var sortingOption in args.SortingOptions)
                {
                    switch (sortingOption.Field)
                    {
                    case "id":
                        orderByList.Add(new Tuple <SortingOption, Expression <Func <Product, object> > >(sortingOption, p => p.Id));
                        break;

                    case "name":
                        orderByList.Add(new Tuple <SortingOption, Expression <Func <Product, object> > >(sortingOption, p => p.Name));
                        break;

                    case "unitPrice":
                        orderByList.Add(new Tuple <SortingOption, Expression <Func <Product, object> > >(sortingOption, p => p.UnitPrice));
                        break;

                    case "category.name":
                        orderByList.Add(new Tuple <SortingOption, Expression <Func <Product, object> > >(sortingOption, p => p.Category.Name));
                        break;
                    }
                }
            }

            if (orderByList.Count == 0)
            {
                orderByList.Add(new Tuple <SortingOption, Expression <Func <Product, object> > >(new SortingOption {
                    Direction = SortingOption.SortingDirection.ASC
                }, p => p.Id));
            }

            //TODO: FilteringOption.Operator will be handled
            var filterList = new List <Tuple <FilteringOption, Expression <Func <Product, bool> > > >();

            if (args.FilteringOptions != null)
            {
                foreach (var filteringOption in args.FilteringOptions)
                {
                    switch (filteringOption.Field)
                    {
                    case "id":
                        filterList.Add(new Tuple <FilteringOption, Expression <Func <Product, bool> > >(filteringOption, p => p.Id == (int)filteringOption.Value));
                        break;

                    case "name":
                        filterList.Add(new Tuple <FilteringOption, Expression <Func <Product, bool> > >(filteringOption, p => p.Name.Contains((string)filteringOption.Value)));
                        break;

                    case "unitPrice":
                        filterList.Add(new Tuple <FilteringOption, Expression <Func <Product, bool> > >(filteringOption, p => p.UnitPrice == (int)filteringOption.Value));
                        break;

                    case "category.name":
                        filterList.Add(new Tuple <FilteringOption, Expression <Func <Product, bool> > >(filteringOption, p => p.Category.Name.Contains((string)filteringOption.Value)));
                        break;
                    }
                }
            }

            var productPagedList = new PagedList <Product>(query, new PagingArgs {
                PageIndex = args.PageIndex, PageSize = args.PageSize, PagingStrategy = args.PagingStrategy
            }, orderByList, filterList);

            return(Task.FromResult <IPagedList <Product> >(productPagedList));
        }
예제 #11
0
        public async Task <ActionResult <IPagedList <ProductDto> > > SearchProducts(PageSearchArgs arg)
        {
            var result = await _mediator.Send(new SearchArticlesCommand(arg));

            return(Ok(result));
        }
        public Task <IPagedList <Category> > SearchCategoriesAsync(PageSearchArgs args)
        {
            var query = Table;

            var orderByList = new List <Tuple <SortingOption, Expression <Func <Category, object> > > >();

            if (args.SortingOptions != null)
            {
                foreach (var sortingOption in args.SortingOptions)
                {
                    switch (sortingOption.Field)
                    {
                    case "id":
                        orderByList.Add(new Tuple <SortingOption, Expression <Func <Category, object> > >(sortingOption, c => c.Id));
                        break;

                    case "name":
                        orderByList.Add(new Tuple <SortingOption, Expression <Func <Category, object> > >(sortingOption, c => c.Name));
                        break;

                    case "description":
                        orderByList.Add(new Tuple <SortingOption, Expression <Func <Category, object> > >(sortingOption, c => c.Description));
                        break;
                    }
                }
            }

            if (orderByList.Count == 0)
            {
                orderByList.Add(new Tuple <SortingOption, Expression <Func <Category, object> > >(new SortingOption {
                    Direction = SortingOption.SortingDirection.ASC
                }, c => c.Id));
            }

            var filterList = new List <Tuple <FilteringOption, Expression <Func <Category, bool> > > >();

            if (args.FilteringOptions != null)
            {
                foreach (var filteringOption in args.FilteringOptions)
                {
                    switch (filteringOption.Field)
                    {
                    case "id":
                        filterList.Add(new Tuple <FilteringOption, Expression <Func <Category, bool> > >(filteringOption, c => c.Id == (int)filteringOption.Value));
                        break;

                    case "name":
                        filterList.Add(new Tuple <FilteringOption, Expression <Func <Category, bool> > >(filteringOption, c => c.Name.Contains((string)filteringOption.Value)));
                        break;

                    case "description":
                        filterList.Add(new Tuple <FilteringOption, Expression <Func <Category, bool> > >(filteringOption, c => c.Description.Contains((string)filteringOption.Value)));
                        break;
                    }
                }
            }

            var categoryPagedList = new PagedList <Category>(query, new PagingArgs {
                PageIndex = args.PageIndex, PageSize = args.PageSize, PagingStrategy = args.PagingStrategy
            }, orderByList, filterList);

            return(Task.FromResult <IPagedList <Category> >(categoryPagedList));
        }
예제 #13
0
 public async Task <ActionResult <IPagedList <ProductResponse> > > Search([FromBody] PageSearchArgs searchArgs)
 {
     return(Ok(await _mediator.Send(new SearchProductsQuery(searchArgs.Args))));
 }
예제 #14
0
        public Task <IPagedList <CoffeeFortuneTelling> > GetUserItemsAsync(PageSearchArgs args, Guid userId)
        {
            IQueryable <CoffeeFortuneTelling> query = _context.CoffeeFortuneTellings
                                                      .Include(a => a.FortuneTeller)
                                                      .Include(b => b.User);

            var orderByList = new List <Tuple <SortingOption, Expression <Func <CoffeeFortuneTelling, object> > > >();

            //if (args.SortingOptions != null)
            //{
            //    foreach (var sortingOption in args.SortingOptions)
            //    {
            //        switch (sortingOption.Field)
            //        {
            //            case "submitDateUtc":
            //                orderByList.Add(new Tuple<SortingOption, Expression<Func<CoffeeFortuneTelling, object>>>(sortingOption, c => c.SubmitDateUtc));
            //                break;
            //        }
            //    }
            //}

            if (orderByList.Count == 0)
            {
                orderByList.Add(new Tuple <SortingOption, Expression <Func <CoffeeFortuneTelling, object> > >(new SortingOption {
                    Direction = SortingOption.SortingDirection.DESC
                }, c => c.SubmitDateUtc));
            }

            var filterList = new List <Tuple <FilteringOption, Expression <Func <CoffeeFortuneTelling, bool> > > >();

            var userFilter = new FilteringOption
            {
                Field    = "",
                Operator = FilteringOption.FilteringOperator.EQ,
                Value    = userId
            };

            filterList.Add(new Tuple <FilteringOption, Expression <Func <CoffeeFortuneTelling, bool> > >(userFilter, c => c.User.Id == (Guid)userFilter.Value));

            if (args.FilteringOptions != null)
            {
                foreach (var filteringOption in args.FilteringOptions)
                {
                    switch (filteringOption.Field)
                    {
                    case "id":
                        filterList.Add(new Tuple <FilteringOption, Expression <Func <CoffeeFortuneTelling, bool> > >(filteringOption, c => c.Id == (Guid)filteringOption.Value));
                        break;

                    case "fortunetellerid":
                        filterList.Add(new Tuple <FilteringOption, Expression <Func <CoffeeFortuneTelling, bool> > >(filteringOption, c => c.FortuneTeller.Id == (Guid)filteringOption.Value));
                        break;

                    case "status":
                        filterList.Add(new Tuple <FilteringOption, Expression <Func <CoffeeFortuneTelling, bool> > >(filteringOption, c => c.Status == (CoffeeFortuneTellingStatus)filteringOption.Value));
                        break;
                    }
                }
            }

            var categoryPagedList = new PagedList <CoffeeFortuneTelling>(query, new PagingArgs {
                PageIndex = args.PageIndex, PageSize = args.PageSize, PagingStrategy = args.PagingStrategy
            }, orderByList, filterList);

            return(Task.FromResult <IPagedList <CoffeeFortuneTelling> >(categoryPagedList));
        }
예제 #15
0
 public async Task <IPagedList <Product> > SearchArticles(PageSearchArgs args)
 {
     return(await _productRepository.SearchAsync(args).ConfigureAwait(false));
 }