-
Notifications
You must be signed in to change notification settings - Fork 1
/
Settings.ascx.cs
88 lines (84 loc) · 3.02 KB
/
Settings.ascx.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System;
using System.IO;
using System.Web.UI.WebControls;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Security.Roles;
using System.Linq;
using System.Collections.Generic;
namespace Connect.DNN.Modules.RoleManager
{
public partial class Settings : ModuleSettingsBase
{
#region Properties
private Common.ModuleSettings _settings;
public Common.ModuleSettings ModSettings
{
get { return _settings ?? (_settings = Common.ModuleSettings.GetSettings(ModuleContext.Configuration)); }
}
#endregion
#region Base Method Implementations
public override void LoadSettings()
{
try
{
if (Page.IsPostBack == false)
{
ddView.Items.Clear();
ddView.Items.Add(new ListItem(LocalizeString("Default"), "Index"));
System.IO.DirectoryInfo viewDir = new DirectoryInfo(Server.MapPath("~/DesktopModules/MVC/Connect/RoleManager/Views"));
foreach (var f in viewDir.GetFiles("*.cshtml"))
{
string vwName = Path.GetFileNameWithoutExtension(f.Name);
if (vwName.ToLower() != "index")
{
ddView.Items.Add(new ListItem(vwName, vwName));
}
}
try
{
ddView.Items.FindByValue(ModSettings.View).Selected = true;
}
catch { }
var rc = new RoleController();
chkRoles.DataSource = rc.GetRoles(PortalId);
chkRoles.DataBind();
var roleIds = ModSettings.RoleListIds().ToList();
foreach (ListItem itm in chkRoles.Items)
{
if (roleIds.Contains(int.Parse(itm.Value)))
{
itm.Selected = true;
}
}
}
}
catch (Exception exc) //Module failed to load
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
public override void UpdateSettings()
{
try
{
ModSettings.View = ddView.SelectedValue;
var roleIds = new List<int>();
foreach (ListItem itm in chkRoles.Items)
{
if (itm.Selected)
{
roleIds.Add(int.Parse(itm.Value));
}
}
ModSettings.RoleList = string.Join(";", roleIds);
ModSettings.SaveSettings(ModuleContext.Configuration);
}
catch (Exception exc) //Module failed to load
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
#endregion
}
}