/// <summary> /// Exclude page controls and data for all pages except for the requested page. /// If the requested page has a summary control. All controls data for other pages will be returned (none will be removed). /// </summary> /// <param name="pageId">The page id passed from the client, which holds special meaning.</param> /// <param name="pages">The list of all pages for the form.</param> /// <returns>The page list to use.</returns> /// <remarks> /// When <paramref name="pageId"/> is <see langword="null"/>, then the return value is all <paramref name="pages"/>. /// When <paramref name="pageId"/> is -1, then the return value is the first page in <paramref name="pages"/>. /// Otherwise the return value is the page that with an id matching <paramref name="pageId"/>. /// </remarks> private PageList RemoveUnecessaryControlsData(int? pageId, PageList pages) { Page currentPage = null; currentPage = !pageId.HasValue || pageId.Value == -1 ? pages[0] : pages.FindByPageId(pageId.Value); if (currentPage == null) { return pages; } if (PageHasSummaryControl(currentPage)) { var summaryControl = currentPage.Controls.FindAllRecursive<SummaryControl>().First(); if (!summaryControl.IncludedControls.All) { foreach (var page in pages) { if (page == currentPage) { continue; } var controls = page.Controls.Where(c => summaryControl.IncludedControls.Controls.Contains(c.Name)); page.Controls = new ControlList(controls); } } } else { pages.Clear(); pages.Add(currentPage); } return pages; }