notification service and user management improvements
This commit is contained in:
161
Oqtane.Client/Modules/Admin/UserProfile/View.razor
Normal file
161
Oqtane.Client/Modules/Admin/UserProfile/View.razor
Normal file
@ -0,0 +1,161 @@
|
||||
@namespace Oqtane.Modules.Admin.UserProfile
|
||||
@inherits ModuleBase
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject IUserRoleService UserRoleService
|
||||
@inject INotificationService NotificationService
|
||||
|
||||
@if (PageState.User != null)
|
||||
{
|
||||
<table class="table table-borderless">
|
||||
<tr>
|
||||
<td>
|
||||
<label for="Name" class="control-label">@title: </label>
|
||||
</td>
|
||||
<td>
|
||||
<select class="form-control" readonly @bind="userid">
|
||||
<option value="-1"><System></option>
|
||||
@if (userroles != null)
|
||||
{
|
||||
foreach (UserRole userrole in userroles)
|
||||
{
|
||||
<option value="@userrole.UserId">@userrole.User.DisplayName</option>
|
||||
}
|
||||
}
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="Name" class="control-label">Subject: </label>
|
||||
</td>
|
||||
<td>
|
||||
<input class="form-control" @bind="@subject" />
|
||||
</td>
|
||||
</tr>
|
||||
@if (title == "From")
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
<label for="Name" class="control-label">Date: </label>
|
||||
</td>
|
||||
<td>
|
||||
<input class="form-control" @bind="@createdon" />
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
<tr>
|
||||
<td>
|
||||
<label for="Name" class="control-label">Message: </label>
|
||||
</td>
|
||||
<td>
|
||||
<textarea class="form-control" @bind="@body" rows="5" />
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
@if (reply != "")
|
||||
{
|
||||
<button type="button" class="btn btn-primary" @onclick="Send">Send</button>
|
||||
}
|
||||
else
|
||||
{
|
||||
if (title == "From")
|
||||
{
|
||||
<button type="button" class="btn btn-primary" @onclick="Reply">Reply</button>
|
||||
}
|
||||
}
|
||||
<NavLink class="btn btn-secondary" href="@NavigateUrl()">Cancel</NavLink>
|
||||
<br />
|
||||
<br />
|
||||
<p>@reply</p>
|
||||
}
|
||||
|
||||
@code {
|
||||
public override SecurityAccessLevel SecurityAccessLevel { get { return SecurityAccessLevel.View; } }
|
||||
public override string Title { get { return "View Notification"; } }
|
||||
|
||||
int notificationid;
|
||||
string title = "";
|
||||
List<UserRole> userroles;
|
||||
string userid = "-1";
|
||||
string subject = "";
|
||||
string createdon = "";
|
||||
string body = "";
|
||||
string reply = "";
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
userroles = await UserRoleService.GetUserRolesAsync(PageState.Site.SiteId);
|
||||
userroles = userroles.Where(item => item.Role.Name == Constants.RegisteredRole || item.Role.Name == Constants.HostRole)
|
||||
.OrderBy(item => item.User.DisplayName).ToList();
|
||||
|
||||
notificationid = Int32.Parse(PageState.QueryString["id"]);
|
||||
Notification notification = await NotificationService.GetNotificationAsync(notificationid);
|
||||
if (notification != null)
|
||||
{
|
||||
if (notification.ToUserId == PageState.User.UserId)
|
||||
{
|
||||
title = "From";
|
||||
if (notification.FromUserId != null)
|
||||
{
|
||||
userid = notification.FromUserId.ToString();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
title = "To";
|
||||
if (notification.ToUserId != null)
|
||||
{
|
||||
userid = notification.ToUserId.ToString();
|
||||
}
|
||||
}
|
||||
subject = notification.Subject;
|
||||
createdon = notification.CreatedOn.ToString();
|
||||
body = notification.Body;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await logger.LogError(ex, "Error Loading Users {Error}", ex.Message);
|
||||
AddModuleMessage("Error Loading Users", MessageType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void Reply()
|
||||
{
|
||||
title = "To";
|
||||
subject = "RE: " + subject;
|
||||
reply = body;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task Send()
|
||||
{
|
||||
Notification notification = new Notification();
|
||||
notification.SiteId = PageState.Site.SiteId;
|
||||
notification.FromUserId = PageState.User.UserId;
|
||||
notification.ToUserId = int.Parse(userid);
|
||||
notification.ToEmail = "";
|
||||
notification.Subject = subject;
|
||||
notification.Body = body;
|
||||
notification.ParentId = notificationid;
|
||||
notification.CreatedOn = DateTime.Now;
|
||||
notification.IsDelivered = false;
|
||||
notification.DeliveredOn = null;
|
||||
|
||||
try
|
||||
{
|
||||
notification = await NotificationService.AddNotificationAsync(notification);
|
||||
|
||||
await logger.LogInformation("Notification Created {Notification}", notification);
|
||||
NavigationManager.NavigateTo(NavigateUrl());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await logger.LogError(ex, "Error Adding Notification {Notification} {Error}", notification, ex.Message);
|
||||
AddModuleMessage("Error Adding Notification", MessageType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user