Example #1
0
 public IActionResult OnGet()
 {
     ViewData["CategoryId"]      = _category.CategoryToList();
     ViewData["ManufacturersId"] = _manufacturers.ManufToList();
     ViewData["MaterialsId"]     = _materials.MaterialToList();
     return(Page());
 }
Example #2
0
        public async Task <IActionResult> OnGetAsync(int id)
        {
            Products = await _db.GetProduct(id); //получаем из БД запись

            if (Products == null)
            {
                return(NotFound());
            }
            ViewData["CategoryId"]      = _category.CategoryToList();
            ViewData["ManufacturersId"] = _manufacturers.ManufToList();
            ViewData["MaterialsId"]     = _materials.MaterialToList();
            return(Page());
        }
Example #3
0
        public async Task <IActionResult> OnGetAsync(decimal PriceFrom,
                                                     decimal PriceTo, SortState?sortState,
                                                     int?MaterialId_select, int?ManufId_select,
                                                     int?pageIndex, string searchString)
        {
            ProductsIQ = _db.GetAllProducts().Where(p => p.Profile.Status == true);
            ViewData["MaterialsId"] = _materials.MaterialToList(); //получаем материалы
            ViewData["ManufId"]     = _manuf.ManufToList();

            //сохраняем состояние фильтрации
            if (sortState != null)
            {
                SortState = sortState;
            }
            if (MaterialId_select != null)
            {
                MaterialIdState = MaterialId_select;
            }
            if (ManufId_select != null)
            {
                ManufIdState = ManufId_select;
            }
            PriceFromState = PriceFrom;
            PriceToState   = PriceTo;
            searchString   = this.searchString;

            //обрабатываем по фильтрам
            FilterPrice(PriceFrom, PriceTo);
            if (searchString != null)
            {
                ProductsIQ = _db.SearchProduct(searchString);
            }
            if (!ProductsIQ.Any()) //проверяем, есть ли что-то
            {
                TempData["Message"] = "Ничего не найдено";
            }
            ProductsIQ = _db.Sorting(ProductsIQ, sortState); //сортировка

            //пагинация
            int pageSize = 9;

            Products = await PaginatedList <Products> .CreateAsync(
                ProductsIQ.AsNoTracking(), pageIndex ?? 1, pageSize); //вызываем метод пагинации

            return(Page());
        }