TenantNotificationInfoExtensions.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using System;
  2. using Abp.Domain.Entities;
  3. using Abp.Extensions;
  4. using Newtonsoft.Json;
  5. namespace Abp.Notifications
  6. {
  7. /// <summary>
  8. /// Extension methods for <see cref="NotificationInfo"/>.
  9. /// </summary>
  10. public static class TenantNotificationInfoExtensions
  11. {
  12. /// <summary>
  13. /// Converts <see cref="NotificationInfo"/> to <see cref="TenantNotification"/>.
  14. /// </summary>
  15. public static TenantNotification ToTenantNotification(this TenantNotificationInfo tenantNotificationInfo)
  16. {
  17. var entityType = tenantNotificationInfo.EntityTypeAssemblyQualifiedName.IsNullOrEmpty()
  18. ? null
  19. : Type.GetType(tenantNotificationInfo.EntityTypeAssemblyQualifiedName);
  20. return new TenantNotification
  21. {
  22. Id = tenantNotificationInfo.Id,
  23. TenantId = tenantNotificationInfo.TenantId,
  24. NotificationName = tenantNotificationInfo.NotificationName,
  25. Data = tenantNotificationInfo.Data.IsNullOrEmpty() ? null : JsonConvert.DeserializeObject(tenantNotificationInfo.Data, Type.GetType(tenantNotificationInfo.DataTypeName)) as NotificationData,
  26. EntityTypeName = tenantNotificationInfo.EntityTypeName,
  27. EntityType = entityType,
  28. EntityId = tenantNotificationInfo.EntityId.IsNullOrEmpty() ? null : JsonConvert.DeserializeObject(tenantNotificationInfo.EntityId, EntityHelper.GetPrimaryKeyType(entityType)),
  29. Severity = tenantNotificationInfo.Severity,
  30. CreationTime = tenantNotificationInfo.CreationTime
  31. };
  32. }
  33. }
  34. }