Add Edit Mode for Administration
This commit is contained in:
@ -11,7 +11,7 @@
|
||||
|
||||
<ModuleMessage Message="@message" />
|
||||
|
||||
@if (profiles != null)
|
||||
@if (PageState.User != null && profiles != null)
|
||||
{
|
||||
<table class="table table-borderless">
|
||||
<tr>
|
||||
@ -55,6 +55,7 @@
|
||||
</table>
|
||||
<button type="button" class="btn btn-primary" @onclick="@SaveUser">Save</button>
|
||||
<button type="button" class="btn btn-secondary" @onclick="@Cancel">Cancel</button>
|
||||
<br /><br />
|
||||
}
|
||||
|
||||
@code {
|
||||
@ -71,10 +72,17 @@
|
||||
{
|
||||
try
|
||||
{
|
||||
displayname = PageState.User.DisplayName;
|
||||
email = PageState.User.Email;
|
||||
profiles = await ProfileService.GetProfilesAsync(ModuleState.SiteId);
|
||||
settings = await SettingService.GetUserSettingsAsync(PageState.User.UserId);
|
||||
if (PageState.User != null)
|
||||
{
|
||||
displayname = PageState.User.DisplayName;
|
||||
email = PageState.User.Email;
|
||||
profiles = await ProfileService.GetProfilesAsync(ModuleState.SiteId);
|
||||
settings = await SettingService.GetUserSettingsAsync(PageState.User.UserId);
|
||||
}
|
||||
else
|
||||
{
|
||||
message = "Current User Is Not Logged In";
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -89,23 +97,30 @@
|
||||
|
||||
private async Task SaveUser()
|
||||
{
|
||||
User user = PageState.User;
|
||||
user.DisplayName = displayname;
|
||||
user.Email = email;
|
||||
await UserService.UpdateUserAsync(user);
|
||||
|
||||
foreach (Profile profile in profiles)
|
||||
try
|
||||
{
|
||||
string value = SettingService.GetSetting(settings, profile.Name, "");
|
||||
await SettingService.UpdateUserSettingsAsync(settings, PageState.User.UserId, profile.Name, value);
|
||||
}
|
||||
User user = PageState.User;
|
||||
user.DisplayName = displayname;
|
||||
user.Email = email;
|
||||
await UserService.UpdateUserAsync(user);
|
||||
|
||||
UriHelper.NavigateTo("");
|
||||
foreach (Profile profile in profiles)
|
||||
{
|
||||
string value = SettingService.GetSetting(settings, profile.Name, "");
|
||||
await SettingService.UpdateUserSettingsAsync(settings, PageState.User.UserId, profile.Name, value);
|
||||
}
|
||||
|
||||
UriHelper.NavigateTo("");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
message = ex.Message;
|
||||
}
|
||||
}
|
||||
|
||||
private void Cancel()
|
||||
{
|
||||
UriHelper.NavigateTo(NavigateUrl("")); // navigate to home
|
||||
UriHelper.NavigateTo(NavigateUrl(""));
|
||||
}
|
||||
|
||||
private void ProfileChanged(UIChangeEventArgs e, string SettingName)
|
||||
|
@ -34,7 +34,7 @@
|
||||
string style = "";
|
||||
bool authorized = false;
|
||||
|
||||
protected override void OnInitialized()
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
text = Action;
|
||||
if (!String.IsNullOrEmpty(Text))
|
||||
@ -49,39 +49,42 @@
|
||||
|
||||
if (!string.IsNullOrEmpty(Class))
|
||||
{
|
||||
classname = Class;
|
||||
classname = Class;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(Style))
|
||||
{
|
||||
style = Style;
|
||||
style = Style;
|
||||
}
|
||||
|
||||
url = EditUrl(Action, parameters);
|
||||
|
||||
string typename = ModuleState.ModuleType.Replace(Utilities.GetTypeNameClass(ModuleState.ModuleType) + ",", Action + ",");
|
||||
Type moduleType = Type.GetType(typename);
|
||||
if (moduleType != null)
|
||||
if (PageState.EditMode)
|
||||
{
|
||||
var moduleobject = Activator.CreateInstance(moduleType);
|
||||
SecurityAccessLevel SecurityAccessLevel = (SecurityAccessLevel)moduleType.GetProperty("SecurityAccessLevel").GetValue(moduleobject, null);
|
||||
switch (SecurityAccessLevel)
|
||||
string typename = ModuleState.ModuleType.Replace(Utilities.GetTypeNameClass(ModuleState.ModuleType) + ",", Action + ",");
|
||||
Type moduleType = Type.GetType(typename);
|
||||
if (moduleType != null)
|
||||
{
|
||||
case SecurityAccessLevel.Anonymous:
|
||||
authorized = true;
|
||||
break;
|
||||
case SecurityAccessLevel.View:
|
||||
authorized = UserSecurity.IsAuthorized(PageState.User, "View", ModuleState.Permissions);
|
||||
break;
|
||||
case SecurityAccessLevel.Edit:
|
||||
authorized = UserSecurity.IsAuthorized(PageState.User, "Edit", ModuleState.Permissions);
|
||||
break;
|
||||
case SecurityAccessLevel.Admin:
|
||||
authorized = UserSecurity.IsAuthorized(PageState.User, Constants.AdminRole);
|
||||
break;
|
||||
case SecurityAccessLevel.Host:
|
||||
authorized = UserSecurity.IsAuthorized(PageState.User, Constants.HostRole);
|
||||
break;
|
||||
var moduleobject = Activator.CreateInstance(moduleType);
|
||||
SecurityAccessLevel SecurityAccessLevel = (SecurityAccessLevel)moduleType.GetProperty("SecurityAccessLevel").GetValue(moduleobject, null);
|
||||
switch (SecurityAccessLevel)
|
||||
{
|
||||
case SecurityAccessLevel.Anonymous:
|
||||
authorized = true;
|
||||
break;
|
||||
case SecurityAccessLevel.View:
|
||||
authorized = UserSecurity.IsAuthorized(PageState.User, "View", ModuleState.Permissions);
|
||||
break;
|
||||
case SecurityAccessLevel.Edit:
|
||||
authorized = UserSecurity.IsAuthorized(PageState.User, "Edit", ModuleState.Permissions);
|
||||
break;
|
||||
case SecurityAccessLevel.Admin:
|
||||
authorized = UserSecurity.IsAuthorized(PageState.User, Constants.AdminRole);
|
||||
break;
|
||||
case SecurityAccessLevel.Host:
|
||||
authorized = UserSecurity.IsAuthorized(PageState.User, Constants.HostRole);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user