public async Task <IActionResult> Index(string category, int pageNumber = 1)
 {
     try
     {
         var list = _productsService.GetProducts(category);
         return(View(await PageinatedList <ProductViewModel> .CreateAsync(list, pageNumber, 10)));
     }
     catch (Exception ex)
     {
         return(RedirectToAction("Error", "Home"));
     }
 }
Пример #2
0
        public IActionResult Product(int gid, int?tid, int?bid)
        {
            if (tid == null && bid == null)
            {
                PageinatedList <ProductViewModel> pages = PageinatedList <ProductViewModel> .CreateAsync(_proService.GetProducts(gid).AsQueryable(), 1, 12);

                return(View(pages));
            }
            else if (tid != null && bid == null)
            {
                PageinatedList <ProductViewModel> pages = PageinatedList <ProductViewModel> .CreateAsync(_proService.GetProductsByType(gid, tid.Value).AsQueryable(), 1, 12);

                return(View(pages));
            }
            else
            {
                PageinatedList <ProductViewModel> pages = PageinatedList <ProductViewModel> .CreateAsync(_proService.GetProductsByBrand(gid, bid.Value).AsQueryable(), 1, 12);

                return(View(pages));
            }
        }
Пример #3
0
        // GET: Peminjamen
        public async Task <IActionResult> Index(string ktsd, string searchString, string currentFilter, int?pageNumber, string sortOrder)
        {
            //untuk search data
            if (!string.IsNullOrEmpty(searchString))
            {
                menu = menu.Where(searchString => s.NoPolisi.Contains(searchString) || s.NamaKendaraan.Contains(searchString) ||
                                  s.NoStnk.Contains(searchString));
            }
            //buat list menyiman ketersediaan
            var ktsdList = new List <string>();
            //query mengambil data
            var ktsdQuery = from d in _context.Kendaraan orderby d.Ketersediaan select d.Ketersediaan;

            ktsdList.AddRange(ktsdQuery.Distinct());

            //untuk menampilkan di view
            ViewBag.ktsd = new SelectList(ktsdList);

            //panggil db context
            var menu = from m in _context.Kendaraan.Include(k => k.IdJenisKendaraanNavigation) select m;

            //untuk memilih dropdownlist ketersediaan
            if (!string.IsNullOrEmpty(ktsd))
            {
                menu = menu.Where(x => x.Ketersediaan == ktsd);
            }

            //membuat pagelist
            ViewData["CurrentSort"] = sortOrder;

            if (searchString != null)
            {
                pageNumber = 1;
            }
            else
            {
                searchString = currentFilter;
            }

            ViewData["CurrentFilter"] = searchString;

            //definisi jumlah data pada halaman
            int pageSize = 5;

            return(View(await PageinatedList <Peminjaman> .CreateAsync(menu.AsNoTracking(), pageNumber ?? 1, pageSize)));

            //untuk sorting
            ViewData["NameSortParm"] = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
            ViewData["DateSortParm"] = sortOrder == "Date" ? "date_desc" : "Date";

            switch (sortOrder)
            {
            case "name_desc":
                menu = menu.OrderByDescending(s => s.IdCustomerNavigation.NamaCustomer);
                break;

            case "Date":
                menu = menu.OrderBy(s => s.TglPeminjaman);
                break;

            case "date_desc":
                menu = menu.OrderByDescending(s => s.TglPeminjaman);
                break;

            default:     //nama ascending
                menu = menu.OrderBy(s => s.IdCustomerNavigation.NamaCustomer);
                break;
            }
        }