Exemplo n.º 1
0
        public async Task <IActionResult> Index(int page = 1, int pageSize = DEFAULT_PAGE_SIZE)
        {
            ClientPagingResult clientsPage = await this._clientService.GetPageAsync(page, pageSize);

            ClientListViewModel clientListViewModel = new ClientListViewModel(clientsPage, page, pageSize);
            int clientsFoundForPage = clientListViewModel.Clients.ToList().Count;

            // retrieve the stored item count (if it exists)
            int    itemCount         = 0;
            string itemCountAsString = this.Request.Cookies[CLIENT_COUNT_COOKIE_KEY];


            // create the ClientListViewModel with appropriate total item account
            if (itemCountAsString != null && int.TryParse(itemCountAsString, out itemCount) &&
                itemCount > clientListViewModel.TotalItemCount && clientsFoundForPage > 0 &&
                clientsPage.HasMore)
            {
                // use the saved total item counts
                clientListViewModel = new ClientListViewModel(clientsPage, page, pageSize, itemCount);
            }

            if (itemCount != clientListViewModel.TotalItemCount && clientsFoundForPage > 0)
            {
                this.Response.Cookies.Append(CLIENT_COUNT_COOKIE_KEY, clientListViewModel.TotalItemCount.ToString());
            }

            return(View("Index", clientListViewModel));
        }
Exemplo n.º 2
0
        public ClientListViewModel(ClientPagingResult clientPagingResult, int pageNumber, int pageSize, int?totalItemCount)
        {
            Clients    = clientPagingResult.Collection;
            PageNumber = pageNumber;
            PageSize   = pageSize;

            if (totalItemCount.HasValue)
            {
                TotalItemCount = totalItemCount.Value;
            }
            else if (clientPagingResult.HasMore)
            {
                TotalItemCount = pageNumber * pageSize + 1;
            }
            else
            {
                TotalItemCount = pageNumber * pageSize;
            }
        }
Exemplo n.º 3
0
 public ClientListViewModel(ClientPagingResult clientPagingResult, int pageNumber, int pageSize) : this(clientPagingResult, pageNumber, pageSize, null)
 {
 }