public IActionResult List(int?minPrice, int?maxPrice, int page = 1) { int ITEM_PER_PAGE_SIZE = 5; int loggedUserId = this.GetClaim <int>(nameof(DataAccess.Entities.User.Id)); // count free apartment int totalAmount = apartmentRepository.Count(BuildFilter(minPrice, maxPrice)); // get free apartment System.Collections.Generic.IEnumerable <Apartment> apartments = apartmentRepository.Get(page: page, amount: ITEM_PER_PAGE_SIZE, filter: BuildFilter(minPrice, maxPrice)); // save previous filter inputs value ViewData[nameof(minPrice)] = minPrice ?? 100; ViewData[nameof(maxPrice)] = maxPrice ?? 1000; ListViewModel listViewModel = new ListViewModel() { UserId = loggedUserId, Apartments = apartments, IsUsersRequest = apartmentRepository.HasRequests(loggedUserId, apartments.Select(a => a.Id).ToArray()), PaginationModel = BuildPagination(ITEM_PER_PAGE_SIZE, page, totalAmount, minPrice, maxPrice) }; return(View(listViewModel)); }
// ACTIONS // GET: Manager/Apartments #region Index public IActionResult Index(int?daysToFree, bool?isFree, int page = 1) { ViewData["Title"] = "Apartments"; // count apartment int totalAmount = apartmentsRepository.Count(BuildFilter(daysToFree, isFree)); // save previous filter inputs value ViewData[nameof(daysToFree)] = daysToFree ?? 90; IndexViewModel indexViewModel = new IndexViewModel { Apartments = apartmentsRepository.Get(page: page, amount: ITEM_PER_PAGE_SIZE, filter: BuildFilter(daysToFree, isFree), includeProperties: nameof(Apartment.Renter)), PaginationModel = BuildPagination(ITEM_PER_PAGE_SIZE, page, totalAmount, daysToFree, isFree), }; return(View(indexViewModel)); }