Example #1
0
        // GET: Orders
        public async Task <IActionResult> Index(SortState sortState, int page = 1)
        {
            OrdersFilterViewModel filter = HttpContext.Session.Get <OrdersFilterViewModel>(filterKey);

            if (filter == null)
            {
                filter = new OrdersFilterViewModel
                {
                    Name = string.Empty
                };
                HttpContext.Session.Set(filterKey, filter);
            }

            string key = $"{typeof(Order).Name}-{page}-{sortState}-{filter.Name}";

            if (!_cache.TryGetValue(key, out OrderViewModel model))
            {
                model = new OrderViewModel();

                IQueryable <Order> orders = getSortedOrders(sortState, filter.Name);

                int count = orders.Count();

                model.PageViewModel = new PageViewModel(page, count, pageSize);

                model.Orders                = count == 0 ? new List <Order>() : orders.Skip((model.PageViewModel.PageIndex - 1) * pageSize).Take(pageSize).ToList();
                model.SortViewModel         = new SortViewModel(sortState);
                model.OrdersFilterViewModel = filter;

                _cache.Set(key, model);
            }

            return(View(model));
        }
Example #2
0
        public IActionResult Index(OrdersFilterViewModel filterModel, int page)
        {
            OrdersFilterViewModel filter = HttpContext.Session.Get <OrdersFilterViewModel>(filterKey);

            if (filter != null)
            {
                filter.Name = filterModel.Name;

                HttpContext.Session.Remove(filterKey);
                HttpContext.Session.Set(filterKey, filter);
            }

            return(RedirectToAction("Index", new { page }));
        }