108 lines
3.6 KiB
Plaintext
108 lines
3.6 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>Mitglieder Suche</h3>
|
|
|
|
<div class="input-group mb-3">
|
|
<input type="text" class="form-control" placeholder="Mitglieder suchen (min 3 Zeichen)..." @bind="_query" @onkeyup="@(e => { if (e.Key == "Enter") Search(); })" />
|
|
<button class="btn btn-primary" @onclick="Search">Suchen</button>
|
|
</div>
|
|
|
|
@if (_searchResults != null)
|
|
{
|
|
@if (_searchResults.Count == 0)
|
|
{
|
|
<p class="text-muted">Keine Mitglieder gefunden.</p>
|
|
}
|
|
else
|
|
{
|
|
<ul class="list-group">
|
|
@foreach (var user in _searchResults)
|
|
{
|
|
<li class="list-group-item d-flex justify-content-between align-items-center">
|
|
<span>
|
|
<strong>@user.DisplayName</strong> <small class="text-muted">(@user.Username)</small>
|
|
</span>
|
|
<button class="btn btn-sm btn-outline-info" @onclick="@(() => InitContact(user))">Kontaktieren</button>
|
|
</li>
|
|
}
|
|
</ul>
|
|
}
|
|
}
|
|
|
|
@if (_selectedUser != null)
|
|
{
|
|
<div class="card mt-4">
|
|
<div class="card-header">Nachricht an: @_selectedUser.DisplayName</div>
|
|
<div class="card-body">
|
|
<div class="mb-3">
|
|
<label>Nachricht</label>
|
|
<textarea class="form-control" rows="3" @bind="_messageBody"></textarea>
|
|
</div>
|
|
<button class="btn btn-primary" @onclick="Send">Nachricht senden</button>
|
|
<button class="btn btn-secondary" @onclick="@(() => _selectedUser = null)">Abbrechen</button>
|
|
|
|
@if (!string.IsNullOrEmpty(_statusMsg))
|
|
{
|
|
<div class="alert alert-info mt-2">@_statusMsg</div>
|
|
}
|
|
</div>
|
|
</div>
|
|
}
|
|
}
|
|
else
|
|
{
|
|
<div class="alert alert-warning">
|
|
Sie müssen Premium Kunde sein um diese Funktion zu nutzen.
|
|
</div>
|
|
}
|
|
|
|
@code {
|
|
public override SecurityAccessLevel SecurityAccessLevel => SecurityAccessLevel.View;
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|