1+ /*==============================================================================================================================
2+ | Author Ignia, LLC
3+ | Client Ignia, LLC
4+ | Project OnTopicSample OnTopic Site
5+ \=============================================================================================================================*/
6+ using System . Threading . Tasks ;
7+ using System . Web . Mvc ;
8+ using OnTopic . Repositories ;
9+ using OnTopic . Web . Mvc . Controllers ;
10+ using OnTopic . Web . Mvc . Models ;
11+ using OnTopic . ViewModels ;
12+ using OnTopic . Mapping . Hierarchical ;
13+
14+ namespace OnTopic . Web . Mvc . Host . Controllers {
15+
16+ /*============================================================================================================================
17+ | CLASS: LAYOUT CONTROLLER
18+ \---------------------------------------------------------------------------------------------------------------------------*/
19+ /// <summary>
20+ /// Provides access to the default homepage for the site.
21+ /// </summary>
22+ public class LayoutController : LayoutControllerBase < NavigationTopicViewModel > {
23+
24+ /*==========================================================================================================================
25+ | PRIVATE FIELDS
26+ \-------------------------------------------------------------------------------------------------------------------------*/
27+ private readonly ITopicRepository _topicRepository = null ;
28+
29+ /*==========================================================================================================================
30+ | CONSTRUCTOR
31+ \-------------------------------------------------------------------------------------------------------------------------*/
32+ /// <summary>
33+ /// Initializes a new instance of a Topic Controller with necessary dependencies.
34+ /// </summary>
35+ /// <returns>A topic controller for loading OnTopic views.</returns>
36+ public LayoutController (
37+ ITopicRoutingService topicRoutingService ,
38+ IHierarchicalTopicMappingService < NavigationTopicViewModel > hierarchicalTopicMappingService ,
39+ ITopicRepository topicRepository
40+ ) : base (
41+ topicRoutingService ,
42+ hierarchicalTopicMappingService
43+ ) {
44+ _topicRepository = topicRepository ;
45+ }
46+
47+ /*==========================================================================================================================
48+ | PAGE LEVEL NAVIGATION
49+ \-------------------------------------------------------------------------------------------------------------------------*/
50+ /// <summary>
51+ /// Provides page-level navigation for the current page.
52+ /// </summary>
53+ public async Task < PartialViewResult > PageLevelNavigation ( ) {
54+
55+ /*------------------------------------------------------------------------------------------------------------------------
56+ | Establish variables
57+ \-----------------------------------------------------------------------------------------------------------------------*/
58+ var currentTopic = CurrentTopic ;
59+ var navigationRootTopic = currentTopic ;
60+
61+ /*------------------------------------------------------------------------------------------------------------------------
62+ | Identify navigation root
63+ >-------------------------------------------------------------------------------------------------------------------------
64+ | The navigation root in the case of the page-level navigation any parent of content type "PageGroup".
65+ \-----------------------------------------------------------------------------------------------------------------------*/
66+ if ( navigationRootTopic != null ) {
67+ while ( navigationRootTopic . Parent != null && ! navigationRootTopic . ContentType . Equals ( "PageGroup" ) ) {
68+ navigationRootTopic = navigationRootTopic . Parent ;
69+ }
70+ }
71+
72+ if ( navigationRootTopic ? . Parent == null ) navigationRootTopic = null ;
73+
74+ /*------------------------------------------------------------------------------------------------------------------------
75+ | Construct view model
76+ \-----------------------------------------------------------------------------------------------------------------------*/
77+ var navigationViewModel = new NavigationViewModel < NavigationTopicViewModel > ( ) {
78+ NavigationRoot = await HierarchicalTopicMappingService . GetRootViewModelAsync ( navigationRootTopic ) ,
79+ CurrentKey = CurrentTopic ? . GetUniqueKey ( )
80+ } ;
81+
82+ /*------------------------------------------------------------------------------------------------------------------------
83+ | Return the corresponding view
84+ \-----------------------------------------------------------------------------------------------------------------------*/
85+ return PartialView ( navigationViewModel ) ;
86+
87+ }
88+
89+ } // Class
90+ } // Namespace
0 commit comments