@namespace Oqtane.Modules.Admin.UserProfile @inherits ModuleBase @inject NavigationManager NavigationManager @inject IUserService UserService @inject IProfileService ProfileService @inject ISettingService SettingService @inject INotificationService NotificationService @if (PageState.User != null && profiles != null) {

@foreach (Profile profile in profiles) { var p = profile; if (p.Category != category) { category = p.Category; } }
@p.Category



@if (filter == "to") {
    From Subject Received
@(context.FromUser == null ? "System" : context.FromUser.DisplayName) @context.Subject @context.CreatedOn @(context.Body.Length > 100 ? context.Body.Substring(0,100) : context.Body)
} else {
    To Subject Sent
@(context.ToUser == null ? context.ToEmail : context.ToUser.DisplayName) @context.Subject @context.CreatedOn @(context.Body.Length > 100 ? context.Body.Substring(0,100) : context.Body)
}

} @code { public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.View; } } string username = ""; string password = ""; string confirm = ""; string email = ""; string displayname = ""; List profiles; Dictionary settings; string category = ""; string filter = "to"; List notifications; protected override async Task OnInitializedAsync() { try { if (PageState.User != null) { username = PageState.User.Username; email = PageState.User.Email; displayname = PageState.User.DisplayName; profiles = await ProfileService.GetProfilesAsync(ModuleState.SiteId); settings = await SettingService.GetUserSettingsAsync(PageState.User.UserId); await LoadNotificationsAsync(); } else { AddModuleMessage("Current User Is Not Logged In", MessageType.Warning); } } catch (Exception ex) { await logger.LogError(ex, "Error Loading User Profile {Error}", ex.Message); AddModuleMessage("Error Loading User Profile", MessageType.Error); } } private async Task LoadNotificationsAsync() { notifications = await NotificationService.GetNotificationsAsync(PageState.Site.SiteId, filter, PageState.User.UserId); notifications = notifications.Where(item => item.DeletedBy != PageState.User.Username).ToList(); } private string GetProfileValue(string SettingName, string DefaultValue) { return SettingService.GetSetting(settings, SettingName, DefaultValue); } private async Task Save() { try { if (password != "" && confirm != "" && email != "") { if (password == confirm) { User user = PageState.User; user.Username = username; user.Password = password; user.Email = email; user.DisplayName = (displayname == "" ? username : displayname); await UserService.UpdateUserAsync(user); await SettingService.UpdateUserSettingsAsync(settings, PageState.User.UserId); await logger.LogInformation("User Profile Saved"); NavigationManager.NavigateTo(NavigateUrl("")); } else { AddModuleMessage("Passwords Entered Do Not Match", MessageType.Warning); } } else { AddModuleMessage("You Must Provide A Username, Password, and Email Address", MessageType.Warning); } } catch (Exception ex) { await logger.LogError(ex, "Error Saving User Profile {Error}", ex.Message); AddModuleMessage("Error Saving User Profile", MessageType.Error); } } private void Cancel() { NavigationManager.NavigateTo(NavigateUrl("")); } private void ProfileChanged(ChangeEventArgs e, string SettingName) { string value = (string)e.Value; settings = SettingService.SetSetting(settings, SettingName, value); } private async Task Delete(Notification Notification) { try { if (!Notification.IsDeleted) { Notification.IsDeleted = true; await NotificationService.UpdateNotificationAsync(Notification); } else { await NotificationService.DeleteNotificationAsync(Notification.NotificationId); } await logger.LogInformation("Notification Deleted {Notification}", Notification); await LoadNotificationsAsync(); StateHasChanged(); } catch (Exception ex) { await logger.LogError(ex, "Error Deleting Notification {Notification} {Error}", Notification, ex.Message); AddModuleMessage(ex.Message, MessageType.Error); } } private async void FilterChanged(ChangeEventArgs e) { filter = (string)e.Value; await LoadNotificationsAsync(); StateHasChanged(); } }