Esempio n. 1
0
        [SetToSession("SortState")] //Фильтр действий для сохранение в сессию состояния сортировки
        public IActionResult Index(SortState sortOrder)
        {
            // Считывание данных из сессии
            var sessionService   = HttpContext.Session.Get("Service");
            var sessionSortState = HttpContext.Session.Get("SortState");

            if (sessionService != null)
            {
                _service = Transformations.DictionaryToObject <ServiceViewModel>(sessionService);
            }
            if ((sessionSortState != null))
            {
                if ((sessionSortState.Count > 0) & (sortOrder == SortState.No))
                {
                    sortOrder = (SortState)Enum.Parse(typeof(SortState), sessionSortState["sortOrder"]);
                }
            }

            // Сортировка и фильтрация данных
            IQueryable <Service> hotelContext = _context.Services;

            hotelContext = Sort_Search(hotelContext, sortOrder, _service.RoomType ?? "", _service.ClientFio ?? "");

            // Формирование модели для передачи представлению
            _service.SortViewModel = new SortViewModel(sortOrder);
            ServicesViewModel services = new ServicesViewModel
            {
                Services         = hotelContext,
                ServiceViewModel = _service
            };

            return(View(services));
        }
Esempio n. 2
0
        public IActionResult Index(int page = 1)
        {
            try
            {
                int                   pageSize     = 5;
                HomeViewModel         entryCache   = memoryCache.Get <HomeViewModel>("Workshop");
                List <OrderViewModel> list         = new List <OrderViewModel>();
                var                   orders       = entryCache.Orders;
                var                   sessionOrder = HttpContext.Session.Get("OrderFilters");
                OrderFilterViewModel  filterOrder  = null;
                if (sessionOrder != null)
                {
                    filterOrder = Transformations.DictionaryToObject <OrderFilterViewModel>(sessionOrder);
                }
                foreach (var order in orders)
                {
                    list.Add(new OrderViewModel
                    {
                        Id             = order.orderID,
                        dateCompletion = order.dateCompletion,
                        dateReceipt    = order.dateReceipt,
                        fioOwner       = order.Car.Owner.fioOwner,
                        fioWorker      = order.Worker.fioWorker,
                        stateNumber    = order.Car.stateNumber,
                        workerID       = order.Worker.workerID,
                        price          = order.Breakdowns.Sum(p => p.Part.price)
                    });
                }
                IQueryable <OrderViewModel> filterList = list.AsQueryable();
                if (filterOrder != null)
                {
                    if (!string.IsNullOrEmpty(filterOrder.Car))
                    {
                        filterList = filterList.Where(p => p.stateNumber == filterOrder.Car);
                    }
                    if (filterOrder.SelectedWorker != null && filterOrder.SelectedWorker != -1)
                    {
                        filterList = filterList.Where(p => p.workerID == filterOrder.SelectedWorker);
                    }
                    switch (filterOrder._selectedType)
                    {
                    case "Отремонтированные":
                    {
                        if (filterOrder._date1 != null)
                        {
                            filterList = filterList.Where(p => p.dateCompletion != null &&
                                                          p.dateCompletion >= filterOrder._date1);
                        }
                        if (filterOrder._date2 != null)
                        {
                            filterList = filterList.Where(p => p.dateCompletion != null &&
                                                          p.dateCompletion <= filterOrder._date2);
                        }
                        break;
                    }

                    case "Поступившие":
                    {
                        if (filterOrder._date1 != null)
                        {
                            filterList = filterList.Where(p => p.dateReceipt >= filterOrder._date1);
                        }
                        if (filterOrder._date2 != null)
                        {
                            filterList = filterList.Where(p => p.dateReceipt <= filterOrder._date2);
                        }
                        break;
                    }
                    }
                }
                var count = filterList.Count();
                var items = filterList.Skip((page - 1) * pageSize).
                            Take(pageSize).ToList();
                if (filterOrder != null)
                {
                    filterOrder.Workers = new SelectList(entryCache.Workers, "workerID", "fioWorker");
                }
                OrdersListViewModel model = new OrdersListViewModel
                {
                    PageViewModel        = new PageViewModel(count, page, pageSize),
                    OrderFilterViewModel = filterOrder == null ? new OrderFilterViewModel(null, entryCache.Workers, null, DateTime.Now, DateTime.Now, null) : filterOrder,
                    Orders = items
                };
                return(View(model));
            }
            catch (Exception ex)
            {
            }
            return(View("Error"));
        }