public static IHtmlControl GetArticleListView(SiteState state, LightObject currentUser, int pageNumber) { int[] allArticleIds = context.Articles.AllObjectIds; int pageCount = BinaryHlp.RoundUp(allArticleIds.Length, articleCountOnPage); int curPos = pageNumber * articleCountOnPage; if (curPos < 0 || curPos >= allArticleIds.Length) { return(new HPanel()); } int[] articleIds = ArrayHlp.GetRange(allArticleIds, curPos, Math.Min(articleCountOnPage, allArticleIds.Length - curPos) ); LightObject[] articleList = ArrayHlp.Convert(articleIds, delegate(int id) { return(new LightObject(context.Articles, id)); } ); IHtmlControl[] items = GetArticleItems(state, articleList); return(new HPanel( Decor.Title("Статьи").MarginBottom(15), new HPanel( new HPanel( items ), ViewJumpHlp.JumpBar("/stati", context.Articles.AllObjectIds.Length, articleCountOnPage, pageNumber) ) )); }
public static T[] GetPageItems <T>(T[] allItems, int itemCountOnPage, int pageNumber) { int pageCount = BinaryHlp.RoundUp(allItems.Length, itemCountOnPage); int curPos = pageNumber * itemCountOnPage; if (curPos < 0 || curPos >= allItems.Length) { return(null); } return(ArrayHlp.GetRange(allItems, curPos, Math.Min(itemCountOnPage, allItems.Length - curPos))); }