Esempio n. 1
0
        public ViewResult List(string category)
        {
            string _category = category;
            IEnumerable <Product> products = null;
            string productCategory         = "";

            if (string.IsNullOrEmpty(category))
            {
                products = _AllProduct.Products.OrderBy(i => i.Id);
            }
            else
            {
                if (string.Equals("Smartphone", category, StringComparison.OrdinalIgnoreCase))
                {
                    products = _AllProduct.Products.Where(i => i.Category.Name.Equals("Smartphone")).OrderBy(i => i.Id);
                }
                else
                {
                    if (string.Equals("Accessories", category, StringComparison.OrdinalIgnoreCase))
                    {
                        products = _AllProduct.Products.Where(i => i.Category.Name.Equals("Accessories")).OrderBy(i => i.Id);
                    }
                }
                productCategory = _category;
            }

            ViewBag.Title = "Product";
            var productObj = new ProductListViewModels
            {
                getAllProduct   = products,
                productCategory = productCategory
            };

            return(View(productObj));
        }
Esempio n. 2
0
        //GET: Home
        public ActionResult Index()
        {
            ProductListViewModels productListViewModels = new ProductListViewModels();

            productListViewModels.ListTabOne   = db.Products.Where(x => x.Gender == Gender.Male).OrderBy(x => x.CreationTime).Take(ITEMS_PER_PAGE).ToList();
            productListViewModels.ListTabTwo   = db.Products.Where(x => x.Gender == Gender.Female).OrderBy(x => x.CreationTime).Take(ITEMS_PER_PAGE).ToList();
            productListViewModels.ListTabThree = db.Products.Where(x => x.CategoryId == 3).OrderBy(x => x.CreationTime).Take(ITEMS_PER_PAGE).ToList();
            productListViewModels.ListTabFour  = db.Products.Where(x => x.CategoryId == 5).OrderBy(x => x.CreationTime).Take(ITEMS_PER_PAGE).ToList();
            return(View(productListViewModels));
        }
Esempio n. 3
0
        public ActionResult Index(string Category = null)

        { // 增加product list
            List <Product>         products;
            List <ProductCategory> categories = productCategories.Collection().ToList();

            if (Category == null)
            {
                products = context.Collection().ToList();
            }
            else
            {
                products = context.Collection().Where(p => p.Category == Category).ToList();
            }
            ProductListViewModels models = new ProductListViewModels();

            models.Products          = products;
            models.productCategories = categories;

            return(View(models));
        }