public ActionResult Index(int?categoryID, string searchTerm, int?pageNo)
        {
            var recordSize = (int)RecordSizeEnums.Size10;

            ProductsListingViewModel model = new ProductsListingViewModel
            {
                SearchTerm = searchTerm,

                Categories = CategoriesService.Instance.GetCategories()
            };

            List <int> selectedCategoryIDs = null;

            if (categoryID.HasValue && categoryID.Value > 0)
            {
                var selectedCategory = model.Categories.FirstOrDefault(x => x.ID == categoryID);

                if (selectedCategory != null)
                {
                    model.CategoryID = selectedCategory.ID;

                    var searchedCategories = CategoryHelpers.GetAllCategoryChildrens(selectedCategory, model.Categories);

                    selectedCategoryIDs = searchedCategories != null?searchedCategories.Select(x => x.ID).ToList() : null;
                }
            }

            model.Products = ProductsService.Instance.SearchProducts(selectedCategoryIDs, searchTerm, null, null, null, pageNo, recordSize, out int count);

            model.Pager = new Pager(count, pageNo, recordSize);

            return(View(model));
        }
Esempio n. 2
0
        public void Can_Paginate()
        {
            //Arange
            Mock <IProductRepository> mock = new Mock <IProductRepository>();

            mock.Setup(m => m.Products).Returns(new Product[]
            {
                new Product {
                    ProductID = 1, Name = "P1"
                },
                new Product {
                    ProductID = 2, Name = "P2"
                },
                new Product {
                    ProductID = 3, Name = "P3"
                },
                new Product {
                    ProductID = 4, Name = "P4"
                },
                new Product {
                    ProductID = 5, Name = "P5"
                }
            });
            ProductController controller = new ProductController(mock.Object);

            controller.PageSize = 3;
            //Act
            ProductsListingViewModel result = controller.List(null, 2).ViewData.Model as ProductsListingViewModel;

            //Assert
            Product[] prodArray = result.Products.ToArray();
            Assert.True(prodArray.Length == 2);
            Assert.Equal("P4", prodArray[0].Name);
            Assert.Equal("P5", prodArray[1].Name);
        }
Esempio n. 3
0
        public ActionResult EntryDetails(string userID)
        {
            ProductsListingViewModel model = new ProductsListingViewModel();

            model.Products = ProductsService.Instance.GetDataEntryProducts(userID);

            return(View(model));
        }
        public IActionResult List(int?categoryId, string search, int page = 1)
        {
            var result = new ProductsListingViewModel
            {
                Products      = this._products.All(categoryId, search, page),
                TotalProducts = this._products.Total(),
                CurrentPage   = page
            };

            @ViewBag.category = this._categories.NameById(categoryId);
            @ViewBag.query    = search;
            return(View(result));
        }
Esempio n. 5
0
        public ActionResult Index(int?categoryID, string searchTerm, int?pageNo)
        {
            var pageSize = ConfigurationsHelper.DashboardRecordsSizePerPage;

            ProductsListingViewModel model = new ProductsListingViewModel();

            model.PageTitle       = "Products";
            model.PageDescription = "Products Listing Page";

            model.SearchTerm = searchTerm;

            model.Categories = CategoriesService.Instance.GetAllCategories();

            model.Suppliers = SuppliersService.Instance.GetAllSuppliers();

            List <int> selectedCategoryIDs = null;

            if (categoryID.HasValue && categoryID.Value > 0)
            {
                var selectedCategory = CategoriesService.Instance.GetCategoryByID(categoryID.Value);

                if (selectedCategory == null)
                {
                    return(HttpNotFound());
                }
                else
                {
                    model.CategoryID = selectedCategory.ID;

                    var searchedCategories = Methods.GetAllCategoryChildrens(selectedCategory, model.Categories);

                    selectedCategoryIDs = searchedCategories != null?searchedCategories.Select(x => x.ID).ToList() : null;
                }
            }

            model.Products = ProductsService.Instance.SearchProducts(selectedCategoryIDs, searchTerm, null, null, null, pageNo, pageSize);
            var totalProducts = ProductsService.Instance.GetProductCount(selectedCategoryIDs, searchTerm, null, null);

            model.Pager = new Pager(totalProducts, pageNo, pageSize);

            return(View(model));
        }
Esempio n. 6
0
        public HttpResponse Index()
        {
            if (this.IsUserLoggedIn())
            {
                var products = new ProductsListingViewModel()
                {
                    Products = this.productsService.GetAll().Select(p => new ProductInfoViewModel
                    {
                        Id       = p.Id,
                        Name     = p.Name,
                        ImageUrl = p.ImageUrl,
                        Price    = p.Price
                    })
                };

                return(this.View(products, "Home"));
            }

            return(this.View());
        }
Esempio n. 7
0
        public void Can_Send_Pagination_View_Model()
        {
            //Arrange
            Mock <IProductRepository> mock = new Mock <IProductRepository>();

            mock.Setup(m => m.Products).Returns(new Product[]
            {
                new Product {
                    ProductID = 1, Name = "P1"
                },
                new Product {
                    ProductID = 2, Name = "P2"
                },
                new Product {
                    ProductID = 3, Name = "P3"
                },
                new Product {
                    ProductID = 4, Name = "P4"
                },
                new Product {
                    ProductID = 5, Name = "P5"
                }
            });
            //Arrange
            ProductController controller = new ProductController(mock.Object)
            {
                PageSize = 3
            };
            //Act
            ProductsListingViewModel result = controller.List(null, 2).ViewData.Model as ProductsListingViewModel;
            //Assert
            PagingInfo pageInfo = result.PagingInfo;

            Assert.Equal(2, pageInfo.CurrentPage);
            Assert.Equal(3, pageInfo.ItemsPerPage);
            Assert.Equal(5, pageInfo.TotalItems);
            Assert.Equal(2, pageInfo.TotalPages);
        }
 public ProductsListing()
 {
     InitializeComponent();
     this.BindingContext = _viewModel = new ProductsListingViewModel();
 }