-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFooterViewComponent.cs
70 lines (61 loc) · 3.84 KB
/
FooterViewComponent.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*==============================================================================================================================
| Author Ignia, LLC
| Client GoldSim
| Project Website
\=============================================================================================================================*/
using GoldSim.Web.Models;
using OnTopic.AspNetCore.Mvc.Components;
using OnTopic.Mapping.Hierarchical;
namespace GoldSim.Web.Components {
/*============================================================================================================================
| CLASS: FOOTER VIEW COMPONENT
\---------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Defines a <see cref="ViewComponent"/> which provides access to a menu of <typeparamref name="NavigationTopicViewModel"/>
/// instances representing the footer of the site.
/// </summary>
public class FooterViewComponent: NavigationTopicViewComponentBase<Models.NavigationTopicViewModel> {
/*==========================================================================================================================
| CONSTRUCTOR
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Initializes a new instance of a <see cref="FooterViewComponent"/> with necessary dependencies.
/// </summary>
/// <returns>A <see cref="FooterViewComponent"/>.</returns>
public FooterViewComponent(
ITopicRepository topicRepository,
IHierarchicalTopicMappingService<Models.NavigationTopicViewModel> hierarchicalTopicMappingService
) : base(
topicRepository,
hierarchicalTopicMappingService
) {
}
/*==========================================================================================================================
| METHOD: INVOKE (ASYNC)
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Provides the footer menu for the site.
/// </summary>
public async Task<IViewComponentResult> InvokeAsync() {
/*------------------------------------------------------------------------------------------------------------------------
| Establish variables
\-----------------------------------------------------------------------------------------------------------------------*/
var navigationRootTopic = TopicRepository.Load("Web:Company");
var webPath = CurrentTopic?.GetWebPath();
var isInWeb = CurrentTopic?.GetUniqueKey().StartsWith("Root:Web", StringComparison.OrdinalIgnoreCase);
var navigationRoot = CurrentTopic?.Attributes.GetValue("NavigationRoot", null, true);
/*------------------------------------------------------------------------------------------------------------------------
| Construct view model
\-----------------------------------------------------------------------------------------------------------------------*/
var navigationViewModel = new FooterViewModel() {
NavigationRoot = await HierarchicalTopicMappingService.GetRootViewModelAsync(navigationRootTopic).ConfigureAwait(true),
CurrentWebPath = webPath,
IsMainSite = navigationRoot?.Equals("Web", StringComparison.OrdinalIgnoreCase)?? isInWeb?? true
};
/*------------------------------------------------------------------------------------------------------------------------
| Return the corresponding view
\-----------------------------------------------------------------------------------------------------------------------*/
return View(navigationViewModel);
}
} // Class
} // Namespace