Admin suite: monitoring dashboard, user management/ban, broadcast, reports, SMS test
- /Admin/Overview: platform monitoring stats (users by role, facilities, listings, applies, push subs, queue, reports, bans) - /Admin/Users: search/filter + ban/unban (User.IsBanned + reason); banned users blocked at login - /Admin/Broadcast: send announcement (in-app + web push) to all / staff / employers via NotificationService - Reports: report button on shift/job detail → /report endpoint → /Admin/Reports (resolve/dismiss) - Settings: 'send test SMS' button; admin cross-nav links; SMS API config already in place - migration AdminBanReports; verified overview/users/broadcast/report persist Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
using JobsMedical.Web.Data;
|
||||
using JobsMedical.Web.Models;
|
||||
using JobsMedical.Web.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace JobsMedical.Web.Pages.Admin;
|
||||
|
||||
[Authorize(Roles = "Admin")]
|
||||
public class BroadcastModel : PageModel
|
||||
{
|
||||
private readonly AppDbContext _db;
|
||||
private readonly NotificationService _notify;
|
||||
|
||||
public BroadcastModel(AppDbContext db, NotificationService notify)
|
||||
{
|
||||
_db = db;
|
||||
_notify = notify;
|
||||
}
|
||||
|
||||
[BindProperty] public string Title { get; set; } = "";
|
||||
[BindProperty] public string? Body { get; set; }
|
||||
[BindProperty] public string? Url { get; set; }
|
||||
[BindProperty] public string Audience { get; set; } = "all"; // all | staff | employers
|
||||
[TempData] public string? Result { get; set; }
|
||||
|
||||
public void OnGet() { }
|
||||
|
||||
public async Task<IActionResult> OnPostAsync()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(Title)) { Result = "عنوان لازم است."; return Page(); }
|
||||
|
||||
IQueryable<User> q = _db.Users.Where(u => !u.IsBanned);
|
||||
q = Audience switch
|
||||
{
|
||||
"staff" => q.Where(u => u.Role == UserRole.Doctor),
|
||||
"employers" => q.Where(u => u.Role == UserRole.FacilityAdmin),
|
||||
_ => q,
|
||||
};
|
||||
var ids = await q.Select(u => u.Id).ToListAsync();
|
||||
await _notify.BroadcastAsync(ids, Title.Trim(), Body?.Trim(), string.IsNullOrWhiteSpace(Url) ? "/" : Url.Trim());
|
||||
|
||||
Result = $"اعلان برای {ids.Count} کاربر ارسال شد (دراپ + پوش در صورت فعالبودن).";
|
||||
return RedirectToPage();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user