public async Task <IActionResult> ItemsAsync( [FromQuery] int pageSize = 10, [FromQuery] int pageIndex = 1, [FromQuery] string searchTerm = null) { if (pageSize <= 0) { pageSize = 10; } if (pageSize > 50) { pageSize = 50; } if (pageIndex <= 0) { pageIndex = 1; } var totalItems = await _catalogBooksRepository.GetTotalCountAsync(searchTerm); var itemsOnPage = await _catalogBooksRepository.GetPageAsync( pageSize, pageIndex, searchTerm); var model = new PaginatedItems <Domain.Model.Book>( pageIndex, pageSize, totalItems, itemsOnPage); return(Ok(model)); }
public async Task GetListUsers_WithPaging_Success() { // Arrange var pageIndex = 0; var pageSize = 10; var userResponseDtos = new List <UserResponseDto>() { new UserResponseDto { Id = "1", Email = "*****@*****.**", FullName = "Test 1", UserName = "******" }, new UserResponseDto { Id = "2", Email = "*****@*****.**", FullName = "Test 2", UserName = "******" } }; var listUsers = new PaginatedItems <UserResponseDto, string>(pageIndex, pageSize, userResponseDtos.Count, userResponseDtos); _userServiceMock.Setup(c => c.ListAsync(pageIndex, pageSize)).ReturnsAsync(listUsers); _usersApiController = new UsersApiController(_userServiceMock.Object, _httpContextAccessorMock.Object); // Act var result = await _usersApiController.Get(0, 10); // Assert var resultValue = ((Microsoft.AspNetCore.Mvc.ObjectResult)result).Value; Assert.NotNull(result); Assert.Equal(listUsers, resultValue); }
public async Task <IActionResult> Get([FromQuery] int pageSize = 10, [FromQuery] int pageIndex = 0) { if (pageSize < 0 || pageSize > 100) { return(BadRequest("The size of the page must be a valid integer between 0 and 100!")); } if (pageIndex < 0 || pageIndex > int.MaxValue) { return(BadRequest($"The index of the page must be a valid integer between 0 and {int.MaxValue}!")); } try { var totalItems = await context.Appointments.LongCountAsync(); var itemsOnPage = await context.Appointments .AsNoTracking() .OrderBy(c => c.Title) .Skip(pageSize * pageIndex) .Take(pageSize) .ToListAsync(); var model = new PaginatedItems <Appointment>( pageIndex, pageSize, totalItems, itemsOnPage); return(Ok(model)); } catch (Exception exc) { return(StatusCode(StatusCodes.Status500InternalServerError, exc.Message)); } }
public async Task GetListBooks_WithPaging_Success() { // Arrange var pageIndex = 0; var pageSize = 10; var bookResponseDtos = new List <BookResponseDto>() { new BookResponseDto { Id = 1, Name = "Book 1", ISBN = "453464567657" }, new BookResponseDto { Id = 2, Name = "Book 2", ISBN = "243547645664" } }; var listBooks = new PaginatedItems <BookResponseDto, int>(pageIndex, pageSize, bookResponseDtos.Count, bookResponseDtos); _bookServiceMock.Setup(c => c.ListAsync(pageIndex, pageSize)).ReturnsAsync(listBooks); _booksApiController = new BooksApiController(_bookServiceMock.Object); // Act var result = await _booksApiController.Get(pageIndex, pageSize); // Assert var resultValue = ((Microsoft.AspNetCore.Mvc.ObjectResult)result).Value; var resultStatus = ((Microsoft.AspNetCore.Mvc.ObjectResult)result).StatusCode; Assert.Equal((int)HttpStatusCode.OK, resultStatus); Assert.Equal(listBooks, resultValue); }
public async Task <IActionResult> GetByIds(string ids, int rowsPerPage = 0, int pageNumber = 1) { IEnumerable <string> idsAsList = JsonConvert.DeserializeObject <IEnumerable <string> >(ids); PaginatedItems <Site> sites = siteService.GetByIds(idsAsList, rowsPerPage, pageNumber); return(Ok(Mapper.Map <PaginatedItemsDto <SiteDetailsDto> >(sites))); }
public async Task <PaginatedItems <TestResultViewModel> > GetItemsAsync( Guid buildId, Status status, string filter, int pageSize, int pageIndex) { var paginatedItems = await _testResultRepository.GetPaginatedItems(buildId, filter, status, pageSize, pageIndex); var paginatedViewModel = new PaginatedItems <TestResultViewModel>( paginatedItems.PageIndex, paginatedItems.PageSize, paginatedItems.Count, Mapper.Map(paginatedItems.Data)); return(paginatedViewModel); }
public IActionResult Items(string name, [FromQuery] int pageSize = 10, [FromQuery] int pageIndex = 0) { using (var db = new CatalogDb()) { long totalItems = db.CatalogItems.Where(c => c.Name.StartsWith(name)).LongCount(); var itemsOnPage = db.CatalogItems.Where(c => c.Name.StartsWith(name)).Skip(pageSize * pageIndex).Take(pageSize).OrderBy(c => c.Name).ToList(); itemsOnPage = ChangeUriPlaceholder(itemsOnPage); var model = new PaginatedItems <CatalogItem>(pageIndex, pageSize, totalItems, itemsOnPage); return(Ok(model)); } }
public async Task <PaginatedItems <PictureViewModel> > Handle(GetPicturesListQuery request, CancellationToken cancellationToken) { var pictures = _context.Pictures.AsQueryable(); var picturesViewModel = _mapper.ProjectTo <PictureViewModel>(pictures); var paginatedPictures2 = PaginatedItems <PictureViewModel> .Create(request.PageIndex, request.PageSize, picturesViewModel); await Task.CompletedTask; return(paginatedPictures2); }
public async Task <PaginatedItems <ManufacturerViewModel> > Handle(GetManufacturersListQuery request, CancellationToken cancellationToken) { var products = GetProductQueryable(); var manufacturersMapped = _mapper.ProjectTo <ManufacturerViewModel>(products); var paginatedProducts = PaginatedItems <ManufacturerViewModel> .Create(request.PageIndex, request.PageSize, manufacturersMapped); await Task.CompletedTask; return(paginatedProducts); }
public async Task <PaginatedItems <CategoryViewModel> > Handle(GetCategoriesListQuery request, CancellationToken cancellationToken) { var categories = _context.Categories.AsQueryable(); var categoriesMapped = _mapper.ProjectTo <CategoryViewModel>(categories); var paginatedCategories = PaginatedItems <CategoryViewModel> .Create(request.PageIndex, request.PageSize, categoriesMapped); await Task.CompletedTask; return(paginatedCategories); }
public static void WriteJsonPaginatedItemsWithoutData <T>(this ITestOutputHelper output, PaginatedItems <T> value) { var truncatedValue = new PaginatedItems <string> { Data = new List <string> { $"Returned files: {value.Data.Count()}. They are not shown in the tests because if they are too much the readability would be bad." }, PageIndex = value.PageIndex, PageSize = value.PageSize, Count = value.Count }; output.WriteLine(JsonConvert.SerializeObject(truncatedValue, Formatting.Indented)); }
public async Task <IActionResult> GetUsuarios([FromQuery] int pageSize = 10, [FromQuery] int pageIndex = 0) { var totalItems = await _context.Usuarios.LongCountAsync(); var items = await _context.Usuarios. OrderBy(u => u.NomeUsuario) .ThenBy(u => u.UltimoNome) .Skip(pageSize * pageIndex) .Take(pageSize) .ToListAsync(); var model = new PaginatedItems <Usuario>(pageIndex, pageSize, totalItems, items); return(Ok(model)); }
public async Task <IActionResult> ItemsAsync([FromQuery] int pageSize = 10, [FromQuery] int pageIndex = 0) { var totalItems = await _catalogContext.Products .LongCountAsync(); var itemsOnPage = await _catalogContext.Products .OrderBy(c => c.Name) .Skip(pageSize * pageIndex) .Take(pageSize) .ToListAsync(); var itemDtos = _mapper.Map <ProductDTO[]>(itemsOnPage); var model = new PaginatedItems <ProductDTO>(pageIndex, pageSize, totalItems, itemDtos); return(Ok(model)); }
public async Task <IActionResult> FindUpcomingAppointments( [FromQuery] int period = 5, [FromQuery] int pageSize = 10, [FromQuery] int pageIndex = 0) { if (period < 1 || period > 530) { return(BadRequest("The period must be a valid integer between 1 and 530 days!")); } if (pageSize < 0 || pageSize > 100) { return(BadRequest("The size of the page must be a valid integer between 0 and 100!")); } if (pageIndex < 0 || pageIndex > int.MaxValue) { return(BadRequest($"The index of the page must be a valid integer between 0 and {int.MaxValue}!")); } try { var now = DateTimeOffset.UtcNow; var end = DateTimeOffset.UtcNow.AddDays(period); var upcomingAppointments = await context.Appointments .Where(a => a.Date.AddYears(now.Year - a.Date.Year) >= now && a.Date.AddYears(now.Year - a.Date.Year) <= end) .ToListAsync(); var totalItems = upcomingAppointments.Count; var itemsOnPage = upcomingAppointments .OrderBy(c => c.Date) .Skip(pageSize * pageIndex) .Take(pageSize) .ToList(); var model = new PaginatedItems <Appointment>( pageIndex, pageSize, totalItems, itemsOnPage); return(Ok(model)); } catch (Exception exc) { return(StatusCode(StatusCodes.Status500InternalServerError, exc.Message)); } }
public IActionResult Items([FromQuery] int pageSize = 10, [FromQuery] int pageIndex = 0) { try { var products = _categoryService.Get(); var mappedItems = products .OrderBy(c => c.Name) .Skip(pageSize * pageIndex) .Take(pageSize); var model = new PaginatedItems <IEnumerable <CategoryViewModel> >(pageIndex, pageSize, products.Count(), mappedItems); return(Ok(model)); } catch (Exception ex) { return(NotFound(new ErrorModel(ex.Message))); } }
public async Task <IActionResult> Get([FromQuery] string filter, [FromQuery] int pageSize = 10, [FromQuery] int pageIndex = 0) { var result = _context.Activities.Where(c => true); var totalItems = await result.LongCountAsync(); var itemsOnPage = await result .Skip(pageIndex *pageSize) .Take(pageSize) .ToListAsync(); var model = new PaginatedItems <ActivityViewModel>(pageIndex, pageSize, totalItems, itemsOnPage.Select(o => new ActivityViewModel { Id = o.Id, Name = o.Name, Description = o.Description })); return(Ok(model)); }
public async Task <IActionResult> Get([FromQuery] string filter, [FromQuery] int pageSize = 10, [FromQuery] int pageIndex = 0) { var processes = _context.Processes.Include(p => p.Nodes) .Include(p => p.States) .Include(p => p.Rules) .Include(p => p.Activities); var totalItems = await processes.LongCountAsync(); var itemsOnPage = await processes.Skip(pageIndex *pageSize) .Take(pageSize) .ToListAsync(); var model = new PaginatedItems <ProcessViewModel>(pageIndex, pageSize, totalItems, itemsOnPage.Select(p => new ProcessViewModel { Actions = _mapper.Map <List <ActionViewModel> >(p.Actions), Name = p.Name })); return(Ok(model)); }
public async Task <IActionResult> Get([FromQuery] int pageIndex = -1, [FromQuery] int pageSize = 5) { var posts = await _postsRepo.GetAllAsync().ToList(); if (pageIndex < 0) { return(Ok(await _postsRepo.GetAllAsync().ToList())); } else { PaginatedItems <BlogPost> pagedPosts = await _postsRepo.GetAllPagedAsync(pageIndex, pageSize); bool isLastPage = false; if (pageIndex >= pagedPosts.TotalItems / pageSize) { isLastPage = true; } pagedPosts.NextPage = (!isLastPage ? Url.Link(null, new { pageIndex = pageIndex + 1, pageSize = pageSize }) : null); return(Ok(pagedPosts)); } }
public async Task <PaginatedItems <BlogPost> > GetAllPagedAsync(int pageIndex, int pageSize, Expression <Func <BlogPost, bool> > filter = null) { var totalItems = await this._context.BlogPosts.CountAsync(); IQueryable <BlogPost> query = _context.BlogPosts; if (filter != null) { query = query.Where(filter); } var posts = await query.OrderByDescending(c => c.Id).Skip(pageIndex * pageSize).Take(pageSize).ToListAsync(); var pagedPosts = new PaginatedItems <BlogPost> { PageIndex = pageIndex, PageSize = pageSize }; pagedPosts.Items = posts; pagedPosts.TotalItems = totalItems; return(pagedPosts); }
public async Task <PaginatedItems <SmartProductViewModel> > Handle(GetProductsListQuery request, CancellationToken cancellationToken) { var products = _context.Set <Product>() .Include(x => x.Category) .Include(x => x.Manufacturer) .AsNoTracking() .AsQueryable(); products = new ProductsQueryBuilder(products) .FilterByPrice(request.Price) .FilterByStockQuantity(request.StockQuantity) .Build(); var productsMapped = _mapper.ProjectTo <SmartProductViewModel>(products); var paginatedProducts = PaginatedItems <SmartProductViewModel> .Create(request.PageIndex, request.PageSize, productsMapped); await Task.CompletedTask; return(paginatedProducts); }
public async Task <PaginatedItems <ProductViewModel> > Handle(GetProductsListQuery request, CancellationToken cancellationToken) { var products = GetProductQueryable(); if (request.CategoryId != null) { products = products.Where(x => x.CategoryId.Equals(request.CategoryId)); } if (request.ManufacturerId != null) { products = products.Where(x => x.ManufacturerId.Equals(request.ManufacturerId)); } var productsMapped = _mapper.ProjectTo <ProductViewModel>(products); var paginatedProducts = PaginatedItems <ProductViewModel> .Create(request.PageIndex, request.PageSize, productsMapped); await Task.CompletedTask; return(paginatedProducts); }
public IActionResult Items(int?catalogTypeId, int?catalogBrandId, [FromQuery] int pageSize = 10, [FromQuery] int pageIndex = 0) { using (var db = new CatalogDb()) { IEnumerable <CatalogItem> items = db.CatalogItems; if (catalogTypeId != null && catalogTypeId > -1) { items = items.Where(r => r.CatalogTypeId == catalogTypeId); } if (catalogBrandId != null && catalogBrandId > -1) { items = items.Where(r => r.CatalogBrandId == catalogBrandId); } long totalItems = items.LongCount(); var itemsOnPage = items.Skip(pageSize * pageIndex).Take(pageSize).OrderBy(c => c.Name).ToList(); itemsOnPage = ChangeUriPlaceholder(itemsOnPage); var model = new PaginatedItems <CatalogItem>(pageIndex, pageSize, totalItems, itemsOnPage); return(Ok(model)); } }
public PaginatedItems ComingSoon(FormDataCollection formData) { AccountService service = new AccountService(db, UserManager); Member member = null; int MemberId = 0; int GameID = 0; int PageNo = 1; int _PAGE_LIMIT = 50; if (this.User.Identity != null) { member = service.findMember(this.User.Identity.Name); } if (member != null) { MemberId = member.MemberID; } if (formData != null) { string pageNumberString = formData.Get("Page"); if (pageNumberString != null) { PageNo = Convert.ToInt32(pageNumberString); } string gameIDString = formData.Get("GameID"); if (gameIDString != null) { GameID = Convert.ToInt32(gameIDString); } } GameService gameService = new GameService(db); List <Game> ComingSoonList = gameService.FindComingSoonGames(MemberId).ToList(); if (ComingSoonList.Count() == 0) { ComingSoonList = gameService.findGlobalGames(MemberId).ToList(); } if (GameID > 0) { PageNo = 1; ComingSoonList = new List <Game>(); // This gets ANY game, not just a coming soon game as per requirement change - 2014-11-27 Game foundGame = db.Games.Find(GameID); if (foundGame != null) { ComingSoonList.Add(foundGame); } } // build models/mobile/Items collection as per requirement. PaginatedItems paginatedItems = new PaginatedItems(); // Add Banner Adverts paginatedItems.BannerAdverts = new List <BannerAdvert>(); // Add items / coming soon / global games paginatedItems.Items = new List <Item>(); int pageCounter = 0; if (ComingSoonList.Count() > 0) { if (ComingSoonList.Count() >= ((_PAGE_LIMIT * PageNo) - _PAGE_LIMIT)) { foreach (Game ComingSoongame in ComingSoonList) { pageCounter++; int currentPage = Math.Abs((_PAGE_LIMIT + pageCounter) / _PAGE_LIMIT); if (currentPage == PageNo) { Item item = new Item(); item.GameCode = ComingSoongame.GameCode; ComingSoongame.Global = (ComingSoongame.Global == null) ? false : (bool)ComingSoongame.Global; { item.GameCountry = (((bool)ComingSoongame.Global) == true) ? "Global" : "South Africa"; } item.GameCurrency = ComingSoongame.ProductInGames.FirstOrDefault().Currency.CurrencyCode; item.GameDescription = ComingSoongame.GameDescription; item.GameExpiryDateTime = ComingSoongame.GameRules.Where(x => x.GameRuleCode.ToUpper() == "RESOLVEACTUALWINNERS").FirstOrDefault().ExcecuteTime.ToString(); item.GameUnlockDateTime = ComingSoongame.GameRules.Where(x => x.GameRuleCode.ToUpper() == "STARTGAME").FirstOrDefault().ExcecuteTime.AddMinutes(-5).ToString(); item.GamePrepareDateTime = ComingSoongame.GameRules.Where(x => x.GameRuleCode.ToUpper() == "PREPAREGAMERULE").FirstOrDefault().ExcecuteTime.ToString(); item.GameResolveWinnersDateTime = ComingSoongame.GameRules.Where(x => x.GameRuleCode.ToUpper() == "RESOLVEACTUALWINNERS").FirstOrDefault().ExcecuteTime.ToString(); item.GameID = ComingSoongame.GameID.ToString(); item.GameName = ComingSoongame.GameName; item.GamePrice = ComingSoongame.ProductInGames.FirstOrDefault().PriceInGame.ToString(); item.GameStatus = ComingSoongame.MemberSubscriptionType1.MemberSubscriptionTypeDescription; switch (item.GameStatus.ToLower().Trim()) { case "bronze": item.GameStatusColor = "#5b4839"; break; case "silver": item.GameStatusColor = "#505054"; break; case "gold": item.GameStatusColor = "#AC882F"; break; case "platinum": item.GameStatusColor = "#424A5B"; break; } item.GameType = ComingSoongame.GameType.GameTypeName; item.LastUpdated = ComingSoongame.DateUpdated.ToString(); // Requirement - 2014-11-27 - Add <FiveMinDeal> Boolean tag if has a five min deal, added NextGame??? properties for futureproofing. item.FiveMinDeal = "0"; if (ComingSoongame.NextGameID != null) { Game nextGame = db.Games.Find(ComingSoongame.NextGameID); item.FiveMinDeal = (nextGame.GameType.GameTypeName.ToLower().Contains("fiveminute")) ? "1" : "0"; item.NextGameID = nextGame.GameID.ToString(); item.NextGameType = nextGame.GameType.GameTypeName; item.NextGameTypeID = nextGame.GameType.GameTypeID.ToString(); } foreach (ProductInGame productInGame in ComingSoongame.ProductInGames) { Product product = productInGame.Product; item.ProductID = product.ProductID.ToString(); item.ProductName = product.ProductName; item.ProductDescription = product.ProductDescription; item.ProductPrice = ((productInGame.ReferencePrice != null) ? (decimal)productInGame.ReferencePrice : 0).ToString(); item.ProductTerms = (product.terms != null) ? product.terms : ""; item.ProductWebsite = ""; // loop through product categories.... because one product can live in multiple categories!!! // I'm only taking the first one at this point. foreach (ProductInCategory productInCategory in product.ProductInCategories) { ProductCategory productCategory = productInCategory.ProductCategory; item.ProductCategory = productCategory.ProductCategoryName; break; } item.ProductImages = new List <ProductImage>(); foreach (Imagedetail image in product.Imagedetails) { ProductImage productImage = new ProductImage(); productImage.ImageID = image.ImageID.ToString(); item.ProductImages.Add(productImage); } } item.TerritoryFlag = "/Content/Images/Flags/South-Africa.png"; if (item.GameCountry.ToLower() == "global") { item.TerritoryFlag = "/Content/Images/Flags/world.png"; } item.TerritoryName = ""; paginatedItems.Items.Add(item); } } } } return(paginatedItems); }
private HtmlHelper <T[]> GetArrayHelper() { if (viewContext_ == null) { viewContext_ = new ViewContext(Context, new FakeView(), ViewData, tempData_, TextWriter.Null); } var helper = new HtmlHelper <T[]>(viewContext_, new GridViewDataContainer <T[]>(PaginatedItems.ToArray(), viewContext_.ViewData)); return(helper); }
public async Task <IActionResult> Get([FromQuery] AlarmFilter filter, [FromQuery] int rowsPerPage = 0, [FromQuery] int pageNumber = 1) { PaginatedItems <Alarm> alarms = alarmService.GetAll(filter, rowsPerPage, pageNumber); return(Ok(Mapper.Map <PaginatedItemsDto <AlarmDetailsDto> >(alarms))); }
private PaginatedItems <BookCategoryResponseDto, int> MapToResponse(PaginatedItems <BookCategory, int> bookCats) { return(new PaginatedItems <BookCategoryResponseDto, int>(bookCats.PageIndex, bookCats.PageSize, bookCats.Count, MapToResponse(bookCats.Data))); }