Request information about movie from IMDB.
using System;
namespace MovieNavigator.Core
{
public class DataPagination : IDataPagination
{
public int PageNumber { get; set; }
public int PageSize { get; set; } = 10;
public int TotalItems { get; set; }
public int TotalPages => (int)Math.Ceiling((double)TotalItems / PageSize);
public int StartPage { get; set; }
public int EndPage { get; set; }
public int ShowMorePrevious { get; set; }
public int ShowMoreNext { get; set; }
public int PreviousPageNumber
{
get
{
if (PageNumber > 1)
return PageNumber - 1;
return 0;
}
}
public int NextPageNumber
{
get
{
if (PageNumber < TotalPages)
return PageNumber + 1;
return 0;
}
}
public string BaseQueryString { get; set; }
public void ProcessData()
{
if (PageNumber == 0)
PageNumber = 1;
StartPage = 1;
EndPage = TotalPages;
if (EndPage > PageSize)
{
var pagesLimitNumber = (int)Math.Ceiling((double)PageNumber / (double)PageSize);
StartPage = pagesLimitNumber * PageSize - PageSize + 1;
EndPage = pagesLimitNumber * PageSize;
if (EndPage > TotalPages)
EndPage = TotalPages;
if (pagesLimitNumber > 1)
ShowMorePrevious = StartPage - 1;
var pagesLimitsCount = (int)Math.Ceiling((double)TotalPages / (double)PageSize);
if (pagesLimitNumber < pagesLimitsCount)
ShowMoreNext = EndPage + 1;
}
}
}
}