コード例 #1
0
        public ActionResult RentProducts(int?page, int?catId = 0)
        {
            //declare a list of products of products vm
            List <RentVM> ListOfProductVM;

            //set page number
            var pageNumber = page ?? 1;

            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                //init the list
                ListOfProductVM = db.Rent_Product.ToArray()
                                  .Where(x => catId == null || catId == 0 || x.CategoryId == catId)
                                  .Select(x => new RentVM(x))
                                  .ToList();

                //populate categories select list
                ViewBag.Categories = new SelectList(db.Rent_Category.ToList(), "Id", "Name");

                //set selected categorey
                ViewBag.SelectCategory = catId.ToString();
            }

            //set pagination

            ViewBag.OnePageOfProducts = ListOfProductVM.ToPagedList(pageNumber, 20);

            //return view with list
            return(View(ListOfProductVM));
        }
コード例 #2
0
        public ActionResult ListOfAuctionProducts(int?page)
        {
            //declare a list of products of products vm
            List <Auction_Product> ListOfProductVM;

            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                ListOfProductVM = db.Auction_Product.ToList();
                foreach (var item in ListOfProductVM)
                {
                    if (item.Auction_Ended == DateTime.Today)
                    {
                        db.Auction_Product.Remove(item);
                        db.SaveChanges();
                    }

                    if (item.LastPrice == null)
                    {
                        item.LastPrice = item.StartingPrice;
                        db.Auction_Product.Add(item);
                    }
                }
            }


            //set page number

            var pageNumber = page ?? 1;


            ViewBag.OnePageOfProducts = ListOfProductVM.ToPagedList(pageNumber, 5);

            //return view with list
            return(View(ListOfProductVM));
        }
コード例 #3
0
        // GET: Admin/Shop/CatagoryshowProducts
        public ActionResult showProducts(int?page, int?CatId)
        {
            //Declare the list of ProductVM
            List <ProductVM> ListOfProductVM;

            //Set the PageNumber
            var PageNumber = page ?? 1;

            using (Db _context = new Db())
            {
                ListOfProductVM = _context.Products.ToArray()
                                  .Where(x => CatId == null || CatId == 0 || x.CatagoryId == CatId)
                                  .Select(x => new ProductVM(x)).ToList();

                //Populate the Catagory Select list

                ViewBag.l_Catagories = new SelectList(_context.Catagories.ToList(), "Id", "Name");

                //Set the Selected Catagories

                ViewBag.SelectedCatagories = CatId.ToString();
            }

            //Set the pagination   (For this we must Install the PagedList.Mvc form Nuget Packages.. and import the Libraty)

            var onePageOfProduct = ListOfProductVM.ToPagedList(PageNumber, 3);

            ViewBag.OnePageOfProduct = onePageOfProduct;

            return(View(ListOfProductVM));
        }
コード例 #4
0
        // GET: AuctionUser
        public ActionResult AuctionProductsList(int?page, int?Id = 0)
        {
            //declare a list of products of products vm
            List <AuctionVM> ListOfProductVM;

            //set page number

            var pageNumber = page ?? 1;

            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                //init the list
                ListOfProductVM = db.Auction_Product.ToArray()
                                  .Select(x => new AuctionVM(x))
                                  .ToList();
            }


            ViewBag.OnePageOfProducts = ListOfProductVM.ToPagedList(pageNumber, 20);


            return(View(ListOfProductVM));
        }
コード例 #5
0
        public ActionResult Products(int?page, int?catId)
        {
            List <ProductVM> ListOfProductVM;

            var pageNumber = page ?? 1;

            using (Db db = new Db())
            {
                ListOfProductVM = db.Products.ToArray()
                                  .Where(x => catId == null || catId == 0 || x.CategoryId == catId)
                                  .Select(x => new ProductVM(x))
                                  .ToList();

                ViewBag.Categories = new SelectList(db.Categories.ToList(), "Id", "Name");

                ViewBag.SelectedCat = catId.ToString();
            }

            var onePageOfProducts = ListOfProductVM.ToPagedList(pageNumber, 3);

            ViewBag.onePageOfProducts = onePageOfProducts;
            return(View(ListOfProductVM));
        }