Ejemplo n.º 1
0
 public List <string> Get(string term)
 {
     return(_productsBL.Get(new ProductsFilter
     {
         Text = term
     }).Entities.Select(x => x.Name).ToList());
 }
Ejemplo n.º 2
0
        private HomePageViewModel BuildHomePageViewModel(string searchTerm, int?parentCategoryId, int?pageNumber)
        {
            HomePageViewModel viewModel = new HomePageViewModel();

            viewModel.RootCategories = _productCategoriesBL.GetCategories(null).Select(productCategory => new HorizontalCategoryItemViewModel
            {
                ProductCategory = productCategory,
                IsSelected      = false
            }).ToList();

            viewModel.SelectedCategory = null;
            ProductsFilter productsFilter = new ProductsFilter
            {
                Text     = searchTerm,
                Publish  = true,
                ParentId = parentCategoryId
            };

            productsFilter.PaginationFilter.PageNumber = pageNumber == null ? 1 : pageNumber.Value;
            productsFilter.PaginationFilter.PageSize   = ApplicationSettings.Instance.AppSettings.DefaultPageSize;

            PagedProductListResult pagedProductListResult = _productsBL.Get(productsFilter);

            viewModel.Products = pagedProductListResult.Entities;
            viewModel.PaginationFilterViewModel = new HomePagePaginationFilterViewModel
            {
                PageNumber       = productsFilter.PaginationFilter.PageNumber,
                TotalRecords     = pagedProductListResult.TotalRecords,
                PageSize         = productsFilter.PaginationFilter.PageSize,
                SearchTerm       = searchTerm,
                ParentCategoryId = parentCategoryId
            };

            if (parentCategoryId.HasValue)
            {
                viewModel.ParentCategories = _productCategoriesBL.GetParentCategories(parentCategoryId.Value);
                viewModel.SelectedCategory = _productCategoriesBL.GetById(parentCategoryId.Value);
                viewModel.ParentCategories.Add(viewModel.SelectedCategory);
                viewModel.ChildCategories = _productCategoriesBL.SearchByFilter(new ProductCategoriesFilter
                {
                    ParentId       = parentCategoryId,
                    IncludeDeleted = false,
                    Publish        = true
                }).Entities;
            }
            else
            {
                viewModel.ParentCategories = new List <ProductCategory>();
                viewModel.ChildCategories  = new List <ProductCategory>();
            }

            return(viewModel);
        }
Ejemplo n.º 3
0
        private void ProcessCategory(List <DynamicNode> nodes, string parentKey, int?parentCategoryId)
        {
            PagedProductCategoryListResult pagedProductCategoryListResult = _productCategoriesBL.SearchByFilter(new ProductCategoriesFilter(int.MaxValue)
            {
                Publish        = true,
                IncludeDeleted = false,
                ParentId       = parentCategoryId
            });

            foreach (ProductCategory productCategory in pagedProductCategoryListResult.Entities)
            {
                DynamicNode productCategoryNode = new DynamicNode
                {
                    ParentKey  = parentKey,
                    Title      = productCategory.Name,
                    Key        = "ProductCategory_" + productCategory.Id,
                    Action     = "Index",
                    Controller = "Home"
                };

                productCategoryNode.RouteValues.Add("parentCategoryId", productCategory.Id);
                nodes.Add(productCategoryNode);

                List <Product> products = _productsBL.Get(new ProductsFilter
                {
                    ParentId = productCategory.Id,
                    Publish  = true
                }).Entities;

                foreach (Product product in products)
                {
                    DynamicNode productNode = new DynamicNode
                    {
                        ParentKey  = productCategoryNode.Key,
                        Title      = product.Name,
                        Key        = productCategoryNode.Key + "_Product_" + product.Id,
                        Controller = "Home",
                        Action     = "Details"
                    };
                    productNode.RouteValues.Add("productId", product.Id);
                    productNode.RouteValues.Add("categoryId", productCategory.Id);

                    nodes.Add(productNode);
                }

                ProcessCategory(nodes, productCategoryNode.Key, productCategory.Id);
            }
        }
Ejemplo n.º 4
0
        public ActionResult Index(ProductsFilterViewModel filter)
        {
            if (TempData[Constants.TempDataKeys.PRODUCTS_FILTER_VIEW_MODEL] != null)
            {
                filter = (ProductsFilterViewModel)TempData[Constants.TempDataKeys.PRODUCTS_FILTER_VIEW_MODEL];
            }

            filter.PageSize = ApplicationSettings.Instance.AppSettings.DefaultPageSize;

            ProductsViewModel model = new ProductsViewModel
            {
                Filter = filter
            };

            if (ModelState.IsValid)
            {
                ModelState.RemoveStateFor(filter, viewModel => filter.Category.Name);
                if (filter.Category.Id.HasValue)
                {
                    filter.Category.Name = _productCategoriesBL.GetById(filter.Category.Id.Value).Name;
                }

                ProductsFilter productsFilter = new ProductsFilter
                {
                    ParentId = filter.Category.Id
                };
                productsFilter.PaginationFilter.PageNumber = filter.PageNumber;
                productsFilter.PaginationFilter.PageSize   = filter.PageSize;

                PagedProductListResult pagedProductListResult = _productsBL.Get(productsFilter);
                model.Filter.TotalRecords = pagedProductListResult.TotalRecords;

                model.Products = pagedProductListResult.Entities.Select(entity => new ProductListItemViewModel
                {
                    Product    = entity,
                    CategoryId = filter.Category.Id
                }).ToList();
            }

            return(View(model));
        }