-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLastModifiedViewComponent.cs
More file actions
76 lines (65 loc) · 4.19 KB
/
LastModifiedViewComponent.cs
File metadata and controls
76 lines (65 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
76
/*==============================================================================================================================
| Author Ignia, LLC
| Client Ignia, LLC
| Project Topics Library
\=============================================================================================================================*/
using System.Globalization;
namespace OnTopic.Editor.AspNetCore.Attributes.LastModifiedAttribute {
/*============================================================================================================================
| CLASS: LAST MODIFIED (VIEW COMPONENT)
\---------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Delivers a view model for a last modified attribute type.
/// </summary>
public class LastModifiedViewComponent: ViewComponent {
/*==========================================================================================================================
| CONSTRUCTOR
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Initializes a new instance of a <see cref="LastModifiedViewComponent"/> with necessary dependencies.
/// </summary>
/// <returns>A topic <see cref="LastModifiedViewComponent"/>.</returns>
public LastModifiedViewComponent() : base() { }
/*==========================================================================================================================
| METHOD: INVOKE
\-------------------------------------------------------------------------------------------------------------------------*/
/// <summary>
/// Assembles the view model for the <see cref="LastModifiedViewComponent"/>.
/// </summary>
public IViewComponentResult Invoke(
EditingTopicViewModel currentTopic,
LastModifiedAttributeDescriptorViewModel attribute,
string htmlFieldPrefix
) {
/*------------------------------------------------------------------------------------------------------------------------
| Validate parameters
\-----------------------------------------------------------------------------------------------------------------------*/
Contract.Requires(currentTopic, nameof(currentTopic));
Contract.Requires(attribute, nameof(attribute));
Contract.Requires(attribute.Key, nameof(attribute.Key));
/*------------------------------------------------------------------------------------------------------------------------
| Set HTML prefix
\-----------------------------------------------------------------------------------------------------------------------*/
ViewData.TemplateInfo.HtmlFieldPrefix = htmlFieldPrefix;
/*------------------------------------------------------------------------------------------------------------------------
| Set model defaults
\-----------------------------------------------------------------------------------------------------------------------*/
currentTopic.Attributes.TryGetValue(attribute.Key, out var currentValue);
if (currentTopic.LastModified != DateTime.MinValue) {
currentValue = currentTopic.LastModified.ToString(CultureInfo.InvariantCulture);
}
var value = DateTime.Now.ToString(CultureInfo.InvariantCulture);
/*------------------------------------------------------------------------------------------------------------------------
| Establish view model
\-----------------------------------------------------------------------------------------------------------------------*/
var model = new LastModifiedAttributeViewModel(currentTopic, attribute) {
CurrentValue = currentValue,
Value = value
};
/*------------------------------------------------------------------------------------------------------------------------
| Return view with view model
\-----------------------------------------------------------------------------------------------------------------------*/
return View(model);
}
} // Class
} // Namespace