HomeController.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System.Threading.Tasks;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Abp;
  4. using Abp.Extensions;
  5. using Abp.Notifications;
  6. using Abp.Timing;
  7. using Abp.Web.Security.AntiForgery;
  8. using VberAdmin.Controllers;
  9. namespace VberAdmin.Web.Host.Controllers;
  10. public class HomeController : VberAdminControllerBase
  11. {
  12. private readonly INotificationPublisher _notificationPublisher;
  13. public HomeController(INotificationPublisher notificationPublisher)
  14. {
  15. _notificationPublisher = notificationPublisher;
  16. }
  17. public IActionResult Index()
  18. {
  19. return Redirect("/doc");
  20. }
  21. /// <summary>
  22. /// This is a demo code to demonstrate sending notification to default tenant admin and host admin uers.
  23. /// Don't use this code in production !!!
  24. /// </summary>
  25. /// <param name="message"></param>
  26. /// <returns></returns>
  27. public async Task<ActionResult> TestNotification(string message = "")
  28. {
  29. if (message.IsNullOrEmpty())
  30. {
  31. message = "This is a test notification, created at " + Clock.Now;
  32. }
  33. var defaultTenantAdmin = new UserIdentifier(1, 2);
  34. var hostAdmin = new UserIdentifier(null, 1);
  35. await _notificationPublisher.PublishAsync(
  36. "App.SimpleMessage",
  37. new MessageNotificationData(message),
  38. severity: NotificationSeverity.Info,
  39. userIds: new[] { defaultTenantAdmin, hostAdmin }
  40. );
  41. return Content("Sent notification: " + message);
  42. }
  43. }