Ejemplo n.º 1
0
        /// <summary>
        /// Get all images
        /// </summary>
        /// <param name="page">current page</param>
        /// <param name="pageSize">number of items to show</param>
        /// <param name="searchQuery">search items by this criteria</param>
        /// <returns>IPaginationModel Instance</returns>
        public virtual async Task <IPaginationModel <Image> > GetImagesAsync(int?page, int pageSize, string searchQuery)
        {
            //Check for unwanted values
            int currentPage = page ?? 1;

            searchQuery = searchQuery ?? string.Empty;

            //Count number of iamge instances in repository
            int totalRecords = await imageRepo.CountAsync();

            //Check if variable currentPage valid
            currentPage = page ?? pgMaker.CheckPageLimits(currentPage, totalRecords, pageSize);

            //Get instances
            int skip      = pgMaker.Skip(currentPage, pageSize);
            var instances = await imageRepo.ListPaginationAsync(skip, pageSize);

            //Prepare pagination model
            var pgOptions = new PaginationOptions(currentPage, totalRecords, pageSize);

            return(pgMaker.PreparePaginationModel(instances, pgOptions));
        }