-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTopicReferenceViewComponent.cs
More file actions
75 lines (64 loc) · 4.19 KB
/
TopicReferenceViewComponent.cs
File metadata and controls
75 lines (64 loc) · 4.19 KB
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
71
72
73
74
75
/*==============================================================================================================================
| Author Ignia, LLC
| Client Ignia, LLC
| Project Topics Library
\=============================================================================================================================*/
namespace OnTopic.Editor.AspNetCore.Attributes.TopicReferenceAttribute {
/*============================================================================================================================
| CLASS: TOPIC REFERENCE (VIEW COMPONENT)
\---------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Delivers a view model for a topic reference attribute type.
/// </summary>
public class TopicReferenceViewComponent : ViewComponent {
/*==========================================================================================================================
| CONSTRUCTOR
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Initializes a new instance of a <see cref="TopicReferenceViewComponent"/> with necessary dependencies.
/// </summary>
public TopicReferenceViewComponent() : base() {
}
/*==========================================================================================================================
| METHOD: INVOKE
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Assembles the view model for the <see cref="TopicReferenceViewComponent"/>.
/// </summary>
public IViewComponentResult Invoke(
EditingTopicViewModel currentTopic,
TopicReferenceAttributeDescriptorViewModel attribute,
string htmlFieldPrefix
) {
/*------------------------------------------------------------------------------------------------------------------------
| Validate parameters
\-----------------------------------------------------------------------------------------------------------------------*/
Contract.Requires(currentTopic, nameof(currentTopic));
Contract.Requires(attribute, nameof(attribute));
/*------------------------------------------------------------------------------------------------------------------------
| Set HTML prefix
\-----------------------------------------------------------------------------------------------------------------------*/
ViewData.TemplateInfo.HtmlFieldPrefix = htmlFieldPrefix;
/*------------------------------------------------------------------------------------------------------------------------
| Set configuration values
\-----------------------------------------------------------------------------------------------------------------------*/
//### TODO 6.0.0: Remove hard-coded reference to BaseTopic; this is only needed for backward compatibility with 5.0.0.
var isBaseTopic = attribute.Key.Equals("BaseTopic", StringComparison.OrdinalIgnoreCase);
if (attribute.UseCurrentContentType || isBaseTopic) {
attribute = attribute with {
AttributeKey = "ContentType",
AttributeValue = currentTopic.ContentType,
AutoPostBack = isBaseTopic? true : attribute.AutoPostBack
};
}
/*------------------------------------------------------------------------------------------------------------------------
| Establish view model
\-----------------------------------------------------------------------------------------------------------------------*/
var viewModel = new AttributeViewModel<TopicReferenceAttributeDescriptorViewModel>(currentTopic, attribute);
/*------------------------------------------------------------------------------------------------------------------------
| Return view with view model
\-----------------------------------------------------------------------------------------------------------------------*/
return View(viewModel);
}
} // Class
} // Namespace