116 lines
3.9 KiB
Plaintext
116 lines
3.9 KiB
Plaintext
@using SZUAbsolventenverein.Module.PremiumArea.Services
|
|
@using Oqtane.Models
|
|
@namespace SZUAbsolventenverein.Module.PremiumArea
|
|
@inherits ModuleBase
|
|
@inject IUserContactService ContactService
|
|
@inject NavigationManager NavigationManager
|
|
|
|
@if (Oqtane.Security.UserSecurity.IsAuthorized(PageState.User, RoleNames.Admin) || Oqtane.Security.UserSecurity.IsAuthorized(PageState.User, "Premium Member"))
|
|
{
|
|
<h3 class="pa-section-title">Mitglieder Suche</h3>
|
|
|
|
<div class="pa-search-group pa-mb-3">
|
|
<input type="text" placeholder="Mitglieder suchen (min 3 Zeichen)..." @bind="_query" @onkeyup="@(e => { if (e.Key == "Enter") Search(); })" />
|
|
<button @onclick="Search">Suchen</button>
|
|
</div>
|
|
|
|
@if (_searchResults != null)
|
|
{
|
|
@if (_searchResults.Count == 0)
|
|
{
|
|
<p class="text-muted">Keine Mitglieder gefunden.</p>
|
|
}
|
|
else
|
|
{
|
|
<div>
|
|
@foreach (var user in _searchResults)
|
|
{
|
|
<div class="pa-user-item">
|
|
<span>
|
|
<span class="pa-user-name">@user.DisplayName</span>
|
|
<span class="pa-user-username">(@user.Username)</span>
|
|
</span>
|
|
<button class="pa-btn pa-btn-outline-info pa-btn-sm" @onclick="@(() => InitContact(user))">Kontaktieren</button>
|
|
</div>
|
|
}
|
|
</div>
|
|
}
|
|
}
|
|
|
|
@if (_selectedUser != null)
|
|
{
|
|
<div class="pa-card pa-mt-4">
|
|
<div class="pa-card-header">Nachricht an: @_selectedUser.DisplayName</div>
|
|
<div class="pa-card-body">
|
|
<div class="pa-mb-3">
|
|
<label class="pa-form-label">Nachricht</label>
|
|
<textarea class="pa-form-control" rows="3" style="width: 100%;" @bind="_messageBody"></textarea>
|
|
</div>
|
|
<div class="pa-d-flex pa-gap-2">
|
|
<button class="pa-btn pa-btn-primary" @onclick="Send">Nachricht senden</button>
|
|
<button class="pa-btn pa-btn-secondary" @onclick="@(() => _selectedUser = null)">Abbrechen</button>
|
|
</div>
|
|
|
|
@if (!string.IsNullOrEmpty(_statusMsg))
|
|
{
|
|
<div class="pa-alert pa-alert-success pa-mt-3">@_statusMsg</div>
|
|
}
|
|
</div>
|
|
</div>
|
|
}
|
|
}
|
|
else
|
|
{
|
|
<div class="pa-alert pa-alert-warning">
|
|
⚠ Sie müssen Premium Kunde sein um diese Funktion zu nutzen.
|
|
</div>
|
|
}
|
|
|
|
@code {
|
|
public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.View;
|
|
|
|
public override List<Resource> Resources => new List<Resource>()
|
|
{
|
|
new Stylesheet("_content/SZUAbsolventenverein.Module.PremiumArea/Module.css")
|
|
};
|
|
|
|
private string _query;
|
|
private List<User> _searchResults;
|
|
private User _selectedUser;
|
|
private string _messageBody;
|
|
private string _statusMsg;
|
|
|
|
private async Task Search()
|
|
{
|
|
if (string.IsNullOrWhiteSpace(_query) || _query.Length < 3) return;
|
|
_searchResults = await ContactService.SearchUsersAsync(_query, ModuleState.ModuleId);
|
|
_selectedUser = null;
|
|
}
|
|
|
|
private void InitContact(User user)
|
|
{
|
|
_selectedUser = user;
|
|
_messageBody = "";
|
|
_statusMsg = "";
|
|
}
|
|
|
|
private async Task Send()
|
|
{
|
|
if (string.IsNullOrWhiteSpace(_messageBody)) return;
|
|
|
|
try
|
|
{
|
|
await ContactService.SendMessageAsync(_selectedUser.UserId, _messageBody, ModuleState.ModuleId);
|
|
_statusMsg = "Message Sent Successully!";
|
|
// Reset after delay or allow closing
|
|
await Task.Delay(2000);
|
|
_selectedUser = null;
|
|
StateHasChanged();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_statusMsg = "Error sending message: " + ex.Message;
|
|
}
|
|
}
|
|
}
|