public App() { RoomsViewModel = new RoomsViewModel(); RoomsFilterViewModel = new RoomsFilterViewModel(); MainPage = new NavigationPage(new HomePageCS()); }
// GET: Rooms public async Task <IActionResult> Index(SortState sortState = SortState.RoomsTypeAsc, int page = 1) { RoomsFilterViewModel filter = HttpContext.Session.Get <RoomsFilterViewModel>(filterKey); if (filter == null) { filter = new RoomsFilterViewModel { Name = string.Empty }; HttpContext.Session.Set(filterKey, filter); } string key = $"{typeof(Room).Name}-{page}-{sortState}-{filter.Name}"; if (!_cache.TryGetValue(key, out RoomViewModel model)) { model = new RoomViewModel(); IQueryable <Room> rooms = GetSortedRooms(sortState, filter.Name); int count = rooms.Count(); model.PageViewModel = new PageViewModel(page, count, pageSize); model.Rooms = count == 0 ? new List <Room>() : rooms.Skip((model.PageViewModel.PageIndex - 1) * pageSize).Take(pageSize).ToList(); model.SortViewModel = new SortViewModel(sortState); model.RoomsFilterViewModel = filter; _cache.Set(key, model); } return(View(model)); }
public IActionResult Index(RoomsFilterViewModel filterModel, int page) { RoomsFilterViewModel filter = HttpContext.Session.Get <RoomsFilterViewModel>(filterKey); if (filter != null) { filter.Name = filterModel.Name; HttpContext.Session.Remove(filterKey); HttpContext.Session.Set(filterKey, filter); } return(RedirectToAction("Index", new { page })); }
private List <Room> Filter(List <Room> collection, RoomsFilterViewModel filterModel) { if (filterModel != null) { if (filterModel.Capacity != null) { collection = collection.Where(x => x.Capacity == filterModel.Capacity).ToList(); } if (filterModel.Type != null) { collection = collection.Where(x => x.Type == (int)filterModel.Type).ToList(); } if (filterModel.IsFree != null) { collection = collection.Where(x => x.IsFree == filterModel.IsFree).ToList(); } } return(collection); }