public PagedList <ProductModel> GetProducts(ProductFilterModel model)
        {
            var prods = GetAll();
            var cates = categoryRepository.GetAll();

            var lst = from prod in prods
                      join cate in cates on prod.CateId equals cate.Id
                      select new ProductModel {
                ProductId    = prod.Id,
                CateId       = cate.Id,
                ProductName  = prod.Name,
                CategoryName = cate.Name,
                Price        = prod.Price
            };

            if (!string.IsNullOrWhiteSpace(model.ProductName))
            {
                lst = lst.Where(m => m.ProductName.Contains(model.ProductName));
            }

            if (model.Price != 0)
            {
                lst = lst.Where(m => m.Price == model.Price);
            }

            return(lst.ToPagedList(model.PageNumber, model.PageSize));
        }
Пример #2
0
        public IHttpActionResult Get(
            [FromUri] ProductFilterModel filter,
            [FromUri] PageInfoModel pageInfo)
        {
            filter   = filter ?? new ProductFilterModel();
            pageInfo = pageInfo ?? new PageInfoModel();
            PagedResult <ProductDto> pagedResult;

            var paging = MappingHelper.MapToPageInfo(pageInfo);

            if (!paging.OrderBy.IsValidFor(_repo.Columns))
            {
                return(BadRequest($"Unknown field : {paging.OrderBy.Name}."));
            }

            if (filter.IsEmpty())
            {
                pagedResult = _repo.PagedQuery(paging);

                return(CreateActionResultFor(pagedResult));
            }

            // Apply filter.
            var query = MapToQuery(filter);

            pagedResult = _repo.PagedQuery(paging, query);

            return(CreateActionResultFor(pagedResult));
        }
Пример #3
0
        public async Task <IList <ProductModel> > GetRelevantProductsAsync(ProductFilterModel criterias)
        {
            if (criterias == null)
            {
                criterias = new ProductFilterModel();
            }

            if (!criterias.Id.HasValue || criterias.Id <= 0)
            {
                return(new List <ProductModel>());
            }

            var filterRequest = new ProductFilter()
            {
                Page     = criterias.Page,
                PageSize = criterias.PageSize.HasValue && criterias.PageSize < _pagerOptions.PageSize ? criterias.PageSize.Value : _pagerOptions.PageSize,
                Keyword  = criterias.Search
            };

            try
            {
                var relevantProducts = await _productService.GetRelevantsAsync(criterias.Id.GetValueOrDefault(), filterRequest);

                var products = await MapProductsResultToModelAsync(relevantProducts);

                return(products);
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #4
0
        public ProductFilter(ProductFilterModel filter)
            : base(x =>
                   (string.IsNullOrEmpty(filter.Search) || x.Name.ToLower().Contains(filter.Search)) &&
                   (!filter.CategoryId.HasValue || x.CategoryId == filter.CategoryId) &&
                   (!filter.TypeId.HasValue || x.ProductTypeId == filter.TypeId)
                   )
        {
            AddInclude(x => x.ProductType);
            AddInclude(x => x.Category);
            AddOrderBy(x => x.Name);
            ApplyPaging(filter.PageSize * (filter.PageIndex - 1), filter.PageSize);

            if (!string.IsNullOrEmpty(filter.Sort))
            {
                switch (filter.Sort)
                {
                case "priceAsc":
                    AddOrderBy(p => p.Price);
                    break;

                case "priceDesc":
                    AddOrderByDescending(p => p.Price);
                    break;

                default:
                    AddOrderBy(n => n.Name);
                    break;
                }
            }
        }
Пример #5
0
        public async Task <ProductModel> GetProductAsync(ClaimsPrincipal claimsPrincipal, ProductFilterModel criterias)
        {
            if (criterias == null)
            {
                criterias = new ProductFilterModel();
            }

            if (!criterias.Id.HasValue || criterias.Id <= 0)
            {
                return(new ProductModel());
            }

            try
            {
                var productResult = await _productService.FindDetailAsync(new IdRequestFilter <long>
                {
                    Id = criterias.Id.GetValueOrDefault(),
                    CanGetInactived = true
                });

                var currentUserId = GetCurrentUserId(claimsPrincipal);
                if (currentUserId != productResult.CreatedById)
                {
                    throw new UnauthorizedAccessException();
                }

                var product = await MapProductResultToModelAsync(productResult);

                return(product);
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #6
0
        public async Task <ProductPageListModel> GetProductsAsync(ProductFilterModel criterias)
        {
            if (criterias == null)
            {
                criterias = new ProductFilterModel();
            }

            var filterRequest = new ProductFilter()
            {
                Page     = criterias.Page,
                PageSize = _pagerOptions.PageSize,
                Keyword  = criterias.Search,
                FarmId   = criterias.FarmId
            };

            try
            {
                var productPageList = await _productService.GetAsync(filterRequest);

                var products = await MapProductsResultToModelAsync(productPageList.Collections);

                var productPage = new ProductPageListModel(products)
                {
                    Filter      = criterias,
                    TotalPage   = productPageList.TotalPage,
                    TotalResult = productPageList.TotalResult
                };

                return(productPage);
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #7
0
        public IEnumerable <Product> getProductByFilter(ProductFilterModel model)
        {
            List <SQLiteParameter> lstParameter = new List <SQLiteParameter>();

            lstParameter.Add(new SQLiteParameter("@NAME", "%" + model.Name + "%"));
            if (model.CreationDateBegin == null)
            {
                lstParameter.Add(new SQLiteParameter("@DATEBEGIN", System.DateTime.MinValue));
            }
            else
            {
                lstParameter.Add(new SQLiteParameter("@DATEBEGIN", model.CreationDateBegin));
            }
            if (model.CreationDateEnd == null)
            {
                lstParameter.Add(new SQLiteParameter("@DATEEND", System.DateTime.MaxValue));
            }
            else
            {
                lstParameter.Add(new SQLiteParameter("@DATEEND", model.CreationDateEnd));
            }

            foreach (var item in Queries.Scripts)
            {
                if (item.Name == "SELECT_BY_FILTER")
                {
                    return(DALHelper <Product> .GetDataReader(item.Value.ToString(), lstParameter, new ProductAdapter()));
                }
            }
            return(new List <Product>());
        }
Пример #8
0
        private async void InitialDataLoading()
        {
            try
            {
                Loader.IsVisible = true;
                List <KeyValuePair <string, string> > parameters = new List <KeyValuePair <string, string> >()
                {
                };

                var jsonstr = await wrapper.GetResponseAsync(Constant.APIs[(int)Constant.APIName.FilterOptionsAPI], parameters);

                if (jsonstr.ToString() == "NoInternet")
                {
                    NoDataPage.IsVisible = true;
                    Loader.IsVisible     = false;
                }

                else
                {
                    Items = JsonConvert.DeserializeObject <ProductFilterModel>(jsonstr);
                    this.BindingContext = Items;
                    Loader.IsVisible    = false;
                }
            }
            catch (Exception ex)
            {
                NoDataPage.IsVisible = true;
                Loader.IsVisible     = false;
                var x = ex.Message;
            }
        }
Пример #9
0
 private static ProductQuery MapToQuery(ProductFilterModel filter) =>
 new ProductQuery
 {
     CreatedBy  = filter.CreatedBy,
     ModifiedBy = filter.ModifiedBy,
     Brand      = filter.Brand,
     Type       = filter.Type
 };
Пример #10
0
 public ProductFilterCountProducts(ProductFilterModel filter)
     : base(x =>
            (string.IsNullOrEmpty(filter.Search) || x.Name.ToLower().Contains(filter.Search)) &&
            (!filter.CategoryId.HasValue || x.CategoryId == filter.CategoryId) &&
            (!filter.TypeId.HasValue || x.ProductTypeId == filter.TypeId)
            )
 {
 }
        /// <summary>
        /// Lấy tất cả sản phẩm theo từ khóa
        /// </summary>
        /// <param name="filter"></param>
        /// <param name="pagination"></param>
        /// <returns></returns>
        public List <ProductCardModel> getProducts(SearchProductFilterModel filter, ref PaginationMetadataModel pagination)
        {
            var productFilter = new ProductFilterModel()
            {
                productSearch = filter.search,
                productSort   = filter.sort
            };

            return(_product.getProducts(productFilter, ref pagination));
        }
        /// <summary>
        /// Lấy product theo bộ lọc
        /// </summary>
        /// <param name="filter"></param>
        /// <param name="pagination"></param>
        /// <returns></returns>
        public List <ProductCardModel> getProducts(HomePageFilterModel filter, ref PaginationMetadataModel pagination)
        {
            var productFilter = new ProductFilterModel()
            {
                categorySlug     = filter.categorySlug,
                categorySlugList = filter.categorySlugList,
                productSort      = filter.sort
            };

            return(_product.getProducts(productFilter, ref pagination));
        }
Пример #13
0
        //[AllowAnonymous]
        public ActionResult Search(ProductFilterModel filter)
        {
            var query = db_set().AsQueryable();

            query = filter_name(query, filter.Name);
            query = filter_artist(query, filter.Name);
            query = filter_tags(query, filter.Tags);
            query = filter_materials(query, filter.Tags);

            return(PartialView("Partial/_GalleryPartial", query.ToList()));
        }
Пример #14
0
        public IActionResult GetProducts([FromQuery] ProductFilterModel model)
        {
            var products = _productService.GetProducts(
                CurrentUserId,
                model.Name, model.PriceFrom,
                model.PriceTo, model.CategoryId,
                null, null, model.PageNumber,
                model.PageSize, model.ArtistId, model.DesignerId,
                model.MechanicsId, model.SortOrder);

            return(Ok(products));
        }
Пример #15
0
        /// <summary>
        /// Lấy tất cả sản phẩm theo filter
        /// </summary>
        /// <param name="filter"></param>
        /// <param name="pagination"></param>
        /// <returns></returns>
        public List <ProductCardModel> getProducts(TagPageFilterModel filter, ref PaginationMetadataModel pagination)
        {
            var productFilter = new ProductFilterModel()
            {
                tagSlug     = filter.tagSlug,
                priceMin    = filter.priceMin,
                priceMax    = filter.priceMax,
                productSort = filter.sort
            };

            return(_product.getProducts(productFilter, ref pagination));
        }
Пример #16
0
        public IPagedList <Product> GetAllProducts(ProductFilterModel model = null, bool forConcreteUser = false, int pageSize = int.MaxValue, int page = 0)
        {
            var query = _productRepository.Table;

            if (forConcreteUser && !_accountService.IsInRole(UserRoles.Admin))
            {
                query = query.Where(p => p.UserId == _accountService.GetUserId());
            }

            if (model != null)
            {
                if (!string.IsNullOrEmpty(model.Processor))
                {
                    query = query.Where(p => p.Processor == model.Processor);
                }

                if (!string.IsNullOrEmpty(model.OperatingSystem))
                {
                    query = query.Where(p => p.OperatingSystem == model.OperatingSystem);
                }

                if (model.Storage.HasValue)
                {
                    query = query.Where(p => p.Storage == model.Storage);
                }

                if (!string.IsNullOrEmpty(model.Name))
                {
                    query = query.Where(p => p.Name.Contains(model.Name));
                }

                if (model.ToPrice.HasValue)
                {
                    query = query.Where(p => p.Price < model.ToPrice);
                }

                if (model.FromPrice.HasValue)
                {
                    query = query.Where(p => p.Price > model.FromPrice);
                }
            }

            query = query.Include(p => p.Pictures);

            var pagedProducts = new PagedList <Product>(
                query,
                page,
                pageSize
                );

            return(pagedProducts);
        }
Пример #17
0
        /// <summary>
        /// Lấy tất cả sản phẩm theo bộ lọc
        /// </summary>
        /// <param name="filter"></param>
        /// <param name="pagination"></param>
        /// <returns></returns>
        public List <ProductCardModel> getProducts(CategoryPageFilterModel filter, ref PaginationMetadataModel pagination)
        {
            var productFilter = new ProductFilterModel()
            {
                categorySlug = filter.categorySlug,
                productBadge = filter.productBadge,
                productSort  = filter.sort,
                priceMin     = filter.priceMin,
                priceMax     = filter.priceMax
            };

            return(_product.getProducts(productFilter, ref pagination));
        }
Пример #18
0
        public static List <Product> getProduct(string sku, int floor, int row, int shelf, int floorShelf)
        {
            var filter = new ProductFilterModel()
            {
                search     = sku,
                floor      = floor,
                row        = row,
                shelf      = shelf,
                floorShelf = floorShelf
            };

            return(ProductController.GetProductShelf(filter));
        }
Пример #19
0
        public IActionResult GetProducts(ProductFilterModel model)
        {
            try
            {
                model.PageNumber = model.PageNumber > 0 ? model.PageNumber : _pageNumber;
                model.PageSize   = model.PageSize > 0 ? model.PageSize : _pageSize;

                var lst = productService.GetProducts(model);

                return(Ok(lst));
            }
            catch (Exception ex)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, ex));
            }
        }
Пример #20
0
        public virtual async Task <IActionResult> Search([FromQuery] ProductFilterModel filter)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Bad query."));
            }

            var result = await _searchControllerService.GetAsync(filter);

            if (result == null)
            {
                return(NotFound());
            }

            return(Ok(result));
        }
Пример #21
0
        public async Task <ProductPageListModel> GetUserProductsAsync(ClaimsPrincipal claimsPrincipal, ProductFilterModel criterias)
        {
            if (criterias == null)
            {
                criterias = new ProductFilterModel();
            }

            if (string.IsNullOrEmpty(criterias.UserIdentityId))
            {
                return(new ProductPageListModel(new List <ProductModel>())
                {
                    Filter = criterias
                });
            }

            var currentUserId = GetCurrentUserId(claimsPrincipal);
            var userId        = await _userManager.DecryptUserIdAsync(criterias.UserIdentityId);

            var filterRequest = new ProductFilter()
            {
                Page            = criterias.Page,
                PageSize        = _pagerOptions.PageSize,
                Keyword         = criterias.Search,
                CreatedById     = userId,
                CanGetInactived = currentUserId == userId
            };

            try
            {
                var productPageList = await _productService.GetAsync(filterRequest);

                var products = await MapProductsResultToModelAsync(productPageList.Collections);

                var productPage = new ProductPageListModel(products)
                {
                    Filter      = criterias,
                    TotalPage   = productPageList.TotalPage,
                    TotalResult = productPageList.TotalResult
                };

                return(productPage);
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #22
0
        public void OverloadFilterPropertiesTest_ReturnedArrayCountShouldBeTwo()
        {
            //Product filter model
            var productFilter = new ProductFilterModel
            {
                CategoryId = 1,
                Categories = new List <int> {
                    3, 4
                },
            };

            //Filter data
            List <Product> result = FilterHelper.Filter(productFilter, ProductsList.AsQueryable()).ToList();

            //assert
            Assert.AreEqual(result.Count(), 2);
        }
Пример #23
0
        public async Task <IActionResult> Index(ProductFilterModel filter)
        {
            var productPageList = await _productService.GetAsync(new ProductFilter
            {
                CreatedById     = filter.CreatedById,
                CreatedDateFrom = filter.CreatedDateFrom,
                CreatedDateTo   = filter.CreatedDateTo,
                Page            = filter.Page,
                PageSize        = _pagerOptions.PageSize,
                Keyword         = filter.Search,
                UpdatedById     = filter.UpdatedById,
                CategoryId      = filter.CategoryId,
                StatusId        = filter.StatusId,
                CanGetDeleted   = true,
                CanGetInactived = true
            });

            var products = productPageList.Collections.Select(x => new ProductModel
            {
                Description = x.Description,
                CreatedBy   = x.CreatedBy,
                CreatedById = x.CreatedById,
                CreatedDate = x.CreatedDate,
                UpdatedBy   = x.UpdatedBy,
                UpdateById  = x.UpdatedById,
                UpdatedDate = x.UpdatedDate,
                Id          = x.Id,
                Name        = x.Name,
                StatusId    = (ProductStatus)x.StatusId,
                PictureId   = x.Pictures.Any() ? x.Pictures.FirstOrDefault().Id : 0
            });

            var productPage = new PageListModel <ProductModel>(products)
            {
                Filter      = filter,
                TotalPage   = productPageList.TotalPage,
                TotalResult = productPageList.TotalResult
            };

            if (_httpHelper.IsAjaxRequest(Request))
            {
                return(PartialView("Partial/_ProductTable", productPage));
            }

            return(View(productPage));
        }
Пример #24
0
        private void BtnFilter_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                ProductBS          productBs = new ProductBS();
                ProductFilterModel model     = new ProductFilterModel();
                model.Name = txtProductName.Text;
                model.CreationDateBegin = dtBegin.SelectedDate;
                model.CreationDateEnd   = dtEnd.SelectedDate;

                productList = productBs.getProductByFilter(model);
            }
            catch (Exception ex)
            {
                MessageBox.Show("ERRO: " + ex.Message);
            }
            grdProduct.ItemsSource = productList;
        }
Пример #25
0
        public ActionResult GetFilter(ProductFilterModel model)
        {
            if (model == null)
            {
                return(RedirectToAction("GetAll"));
            }
            ProductDTO product = new ProductDTO
            {
                Name  = model.Name,
                Year  = model.MinYear,
                Price = model.MinPrice ?? 0,
                Model = model.CarModel,
                Fuel  = model.Fuel
            };
            var list = _productService.GetFilter(product, model.MaxYear, model.MaxPrice ?? int.MaxValue);

            return(View("GetAll", list.ToPagedList(1, 5)));
        }
Пример #26
0
        public void LoadData()
        {
            string TextSearch = "";
            int    Page       = 1;
            double Price      = 0;

            if (Request.QueryString["textsearch"] != null)
            {
                TextSearch = Request.QueryString["textsearch"].Trim();
            }
            if (Request.QueryString["price"] != null)
            {
                Price = Convert.ToDouble(Request.QueryString["price"]);
            }
            if (Request.QueryString["Page"] != null)
            {
                Page = Request.QueryString["Page"].ToInt();
            }

            // Create order fileter
            var filter = new ProductFilterModel()
            {
                category     = 44,
                stockStatus  = 1,
                quantity     = "greaterthan",
                quantityFrom = 3,
                search       = TextSearch,
                price        = Price
            };

            // Create pagination
            var page = new PaginationMetadataModel()
            {
                currentPage = Page,
                pageSize    = 20
            };
            List <ProductSQL> a = new List <ProductSQL>();

            a = ProductController.GetAllSql(filter, ref page);

            pagingall(a, page);
        }
Пример #27
0
        static void Main(string[] args)
        {
            //Product filter model
            var productFilter = new ProductFilterModel
            {
                Captions = new List <string>()
                {
                    "Apple", "Pear"
                },
                Price           = 3,
                ReceiveDateFrom = new DateTime(2019, 05, 07),
                ReceiveDateTo   = new DateTime(2019, 07, 07),
                CategoryId      = 1,
                Categories      = new List <int> {
                    3, 4
                },
                CardTariffIds = new List <int> {
                    1, 3
                },
                CreditCategoryIds = new List <int> {
                    4, 3
                },
                AccountTariffIds = new List <int> {
                    2, 4, 7
                },
                IsAllTariff = true
            };

            //Filter data
            IQueryable <Product> result = FilterHelper.Filter(productFilter, ProductsList.AsQueryable());


            //Show filtered data
            foreach (var item in result.ToList())
            {
                Console.WriteLine($"Name: {item.Caption}, Description: {item.Description}, Price: {item.Price}, Quantity: {item.Quantity}, ReceiveDate: {item.ReceiveDate}, CategoryId: {item.CategoryId}");
            }


            Console.ReadKey();
        }
Пример #28
0
        public void BasicFilterTest_ReturnedArrayCountShouldBeOne()
        {
            //Product filter model
            var productFilter = new ProductFilterModel
            {
                Captions = new List <string>()
                {
                    "Apple", "Pear"
                },
                Price           = 3,
                ReceiveDateFrom = new DateTime(2019, 05, 04),
                ReceiveDateTo   = new DateTime(2019, 07, 07),
                CategoryId      = 1
            };

            //Filter data
            List <Product> result = FilterHelper.Filter(productFilter, ProductsList.AsQueryable()).ToList();

            //assert
            Assert.AreEqual(result.Count(), 1);
        }
Пример #29
0
        /// <summary>
        /// Страница со списоком товаров
        /// </summary>
        /// <returns></returns>
        public ActionResult Index(ProductFilterModel request)
        {
            SetSitePageSettings(EnumSitePage.Products);
            const int take     = 21;
            var       products = _productService.GetProducts(request);

            if (!request.Page.HasValue)
            {
                request.Page = 1;
            }
            if (request.CategoriesId == null)
            {
                request.CategoriesId = new List <int>();
            }
            // если не существует такой страницы
            if (request.Page > products.Count / take + 1)
            {
                request.Page = 1;
            }

            var model = new ProductsViewModel()
            {
                Products   = products,
                Brands     = _productService.GetAllBrandsBase(),
                Pagination = new PaginationModel(take)
                {
                    Count      = products.Count,
                    Skip       = ((int)request.Page - 1) * take,
                    Take       = take,
                    PageNumber = (int)request.Page,
                    PageSize   = (int)Math.Round(products.Count / Convert.ToDecimal(take))
                },
                Filter     = request,
                Categories = _categoryService.GetAllCategories(),
                Tags       = _productService.GetTagsForFilter(products)
            };

            model.Products = model.Products.Skip(model.Pagination.Skip).Take(model.Pagination.Take).ToList();
            return(View(model));
        }
Пример #30
0
        public void GetAllProducts_Filter()
        {
            //arrange
            var nameFilterModel = new ProductFilterModel {
                Name = "P2"
            };
            var processorFilterModel = new ProductFilterModel {
                Processor = "i3"
            };
            var operatingSystemFilterModel = new ProductFilterModel {
                OperatingSystem = "Linux"
            };

            //act
            var filteredByName           = _productService.GetAllProducts(nameFilterModel);
            var filteredByProcessor      = _productService.GetAllProducts(processorFilterModel);
            var filteredByOpertingSystem = _productService.GetAllProducts(operatingSystemFilterModel);

            //assert
            Assert.Equal(2, filteredByName.Count);
            Assert.Equal(3, filteredByProcessor.Count);
            Assert.Single(filteredByOpertingSystem);
        }