-
-
Notifications
You must be signed in to change notification settings - Fork 780
Expand file tree
/
Copy pathModuleControlController.cs
More file actions
172 lines (155 loc) · 9.25 KB
/
Copy pathModuleControlController.cs
File metadata and controls
172 lines (155 loc) · 9.25 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information
namespace DotNetNuke.Entities.Modules
{
using System;
using System.Collections.Generic;
using System.Linq;
using DotNetNuke.Abstractions.Application;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Data;
using DotNetNuke.Entities.Users;
using DotNetNuke.Internal.SourceGenerators;
using Microsoft.Extensions.DependencyInjection;
/// <summary>ModuleControlController provides the Business Layer for Module Controls.</summary>
public partial class ModuleControlController
{
private const string Key = "ModuleControlID";
private static readonly DataProvider DataProvider = DataProvider.Instance();
/// <summary>AddModuleControl adds a new Module Control to the database.</summary>
/// <param name="objModuleControl">The Module Control to save.</param>
public static void AddModuleControl(ModuleControlInfo objModuleControl)
{
SaveModuleControl(objModuleControl, true);
}
/// <summary>DeleteModuleControl deletes a Module Control in the database.</summary>
/// <param name="moduleControlID">The ID of the Module Control to delete.</param>
public static void DeleteModuleControl(int moduleControlID)
{
DataProvider.DeleteModuleControl(moduleControlID);
DataCache.ClearHostCache(true);
}
/// <summary>GetModuleControl gets a single Module Control from the database.</summary>
/// <param name="moduleControlID">The ID of the Module Control to fetch.</param>
/// <returns>The <see cref="ModuleControlInfo"/> or <see langword="null"/>.</returns>
[DnnDeprecated(10, 2, 4, "Use overload taking IHostSettings")]
public static partial ModuleControlInfo GetModuleControl(int moduleControlID)
=> GetModuleControl(Globals.GetCurrentServiceProvider().GetRequiredService<IHostSettings>(), moduleControlID);
/// <summary>GetModuleControl gets a single Module Control from the database.</summary>
/// <param name="hostSettings">The host settings.</param>
/// <param name="moduleControlId">The ID of the Module Control to fetch.</param>
/// <returns>The <see cref="ModuleControlInfo"/> or <see langword="null"/>.</returns>
public static ModuleControlInfo GetModuleControl(IHostSettings hostSettings, int moduleControlId)
{
return (from kvp in GetModuleControls(hostSettings)
where kvp.Key == moduleControlId
select kvp.Value)
.FirstOrDefault();
}
/// <summary>Gets a Dictionary of Module Controls by Module Definition.</summary>
/// <param name="moduleDefID">The ID of the Module Definition.</param>
/// <returns>A <see cref="Dictionary{TKey,TValue}"/> mapping control key to <see cref="ModuleControlInfo"/>.</returns>
[DnnDeprecated(10, 2, 4, "Use overload taking IHostSettings")]
public static partial Dictionary<string, ModuleControlInfo> GetModuleControlsByModuleDefinitionID(int moduleDefID)
=> GetModuleControlsByModuleDefinitionID(Globals.GetCurrentServiceProvider().GetRequiredService<IHostSettings>(), moduleDefID);
/// <summary>Gets a Dictionary of Module Controls by Module Definition.</summary>
/// <param name="hostSettings">The host settings.</param>
/// <param name="moduleDefId">The ID of the Module Definition.</param>
/// <returns>A <see cref="Dictionary{TKey,TValue}"/> mapping control key to <see cref="ModuleControlInfo"/>.</returns>
public static Dictionary<string, ModuleControlInfo> GetModuleControlsByModuleDefinitionID(IHostSettings hostSettings, int moduleDefId)
{
return GetModuleControls(hostSettings).Where(kvp => kvp.Value.ModuleDefID == moduleDefId)
.ToDictionary(kvp => kvp.Value.ControlKey, kvp => kvp.Value);
}
/// <summary>GetModuleControlByControlKey gets a single Module Control from the database.</summary>
/// <param name="controlKey">The key for the control.</param>
/// <param name="moduleDefID">The ID of the Module Definition.</param>
/// <returns>The <see cref="ModuleControlInfo"/> or <see langword="null"/>.</returns>
[DnnDeprecated(10, 2, 4, "Use overload taking IHostSettings")]
public static partial ModuleControlInfo GetModuleControlByControlKey(string controlKey, int moduleDefID)
=> GetModuleControlByControlKey(Globals.GetCurrentServiceProvider().GetRequiredService<IHostSettings>(), controlKey, moduleDefID);
/// <summary>GetModuleControlByControlKey gets a single Module Control from the database.</summary>
/// <param name="hostSettings">The host settings.</param>
/// <param name="controlKey">The key for the control.</param>
/// <param name="moduleDefId">The ID of the Module Definition.</param>
/// <returns>The <see cref="ModuleControlInfo"/> or <see langword="null"/>.</returns>
public static ModuleControlInfo GetModuleControlByControlKey(IHostSettings hostSettings, string controlKey, int moduleDefId)
{
return (from kvp in GetModuleControls(hostSettings)
where kvp.Value.ControlKey.Equals(controlKey, StringComparison.OrdinalIgnoreCase)
&& kvp.Value.ModuleDefID == moduleDefId
select kvp.Value)
.FirstOrDefault();
}
/// <summary>SaveModuleControl updates a Module Control in the database.</summary>
/// <param name="moduleControl">The Module Control to save.</param>
/// <param name="clearCache">A flag that determines whether to clear the host cache.</param>
/// <returns>The module control ID.</returns>
public static int SaveModuleControl(ModuleControlInfo moduleControl, bool clearCache)
{
int moduleControlID = moduleControl.ModuleControlID;
if (moduleControlID == Null.NullInteger)
{
// Add new Module Definition
moduleControlID = DataProvider.AddModuleControl(
moduleControl.ModuleDefID,
moduleControl.ControlKey,
moduleControl.ControlTitle,
moduleControl.ControlSrc,
moduleControl.MvcControlClass,
moduleControl.IconFile,
(int)moduleControl.ControlType,
moduleControl.ViewOrder,
moduleControl.HelpURL,
moduleControl.SupportsPartialRendering,
moduleControl.SupportsPopUps,
UserController.Instance.GetCurrentUserInfo().UserID);
}
else
{
// Upgrade Module Control
DataProvider.UpdateModuleControl(
moduleControl.ModuleControlID,
moduleControl.ModuleDefID,
moduleControl.ControlKey,
moduleControl.ControlTitle,
moduleControl.ControlSrc,
moduleControl.MvcControlClass,
moduleControl.IconFile,
(int)moduleControl.ControlType,
moduleControl.ViewOrder,
moduleControl.HelpURL,
moduleControl.SupportsPartialRendering,
moduleControl.SupportsPopUps,
UserController.Instance.GetCurrentUserInfo().UserID);
}
if (clearCache)
{
DataCache.ClearHostCache(true);
}
return moduleControlID;
}
/// <summary>UpdateModuleControl updates a Module Control in the database.</summary>
/// <param name="objModuleControl">The Module Control to save.</param>
public static void UpdateModuleControl(ModuleControlInfo objModuleControl)
{
SaveModuleControl(objModuleControl, true);
}
/// <summary>GetModuleControls gets a Dictionary of Module Controls from the Cache.</summary>
private static Dictionary<int, ModuleControlInfo> GetModuleControls(IHostSettings hostSettings)
{
return CBO.GetCachedObject<Dictionary<int, ModuleControlInfo>>(
hostSettings,
new CacheItemArgs(DataCache.ModuleControlsCacheKey, DataCache.ModuleControlsCacheTimeOut, DataCache.ModuleControlsCachePriority),
GetModuleControlsCallBack);
}
/// <summary>GetModuleControlsCallBack gets a Dictionary of Module Controls from the Database.</summary>
/// <param name="cacheItemArgs">The CacheItemArgs object that contains the parameters needed for the database call.</param>
private static object GetModuleControlsCallBack(CacheItemArgs cacheItemArgs)
{
return CBO.FillDictionary(Key, DataProvider.GetModuleControls(), new Dictionary<int, ModuleControlInfo>());
}
}
}