UserNotificationManager.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Abp.Dependency;
  6. namespace Abp.Notifications
  7. {
  8. /// <summary>
  9. /// Implements <see cref="IUserNotificationManager"/>.
  10. /// </summary>
  11. public class UserNotificationManager : IUserNotificationManager, ISingletonDependency
  12. {
  13. private readonly INotificationStore _store;
  14. /// <summary>
  15. /// Initializes a new instance of the <see cref="UserNotificationManager"/> class.
  16. /// </summary>
  17. public UserNotificationManager(INotificationStore store)
  18. {
  19. _store = store;
  20. }
  21. public async Task<List<UserNotification>> GetUserNotificationsAsync(UserIdentifier user, UserNotificationState? state = null, int skipCount = 0, int maxResultCount = int.MaxValue)
  22. {
  23. var userNotifications = await _store.GetUserNotificationsWithNotificationsAsync(user, state, skipCount, maxResultCount);
  24. return userNotifications
  25. .Select(un => un.ToUserNotification())
  26. .ToList();
  27. }
  28. public Task<int> GetUserNotificationCountAsync(UserIdentifier user, UserNotificationState? state = null)
  29. {
  30. return _store.GetUserNotificationCountAsync(user, state);
  31. }
  32. public async Task<UserNotification> GetUserNotificationAsync(int? tenantId, Guid userNotificationId)
  33. {
  34. var userNotification = await _store.GetUserNotificationWithNotificationOrNullAsync(tenantId, userNotificationId);
  35. if (userNotification == null)
  36. {
  37. return null;
  38. }
  39. return userNotification.ToUserNotification();
  40. }
  41. public Task UpdateUserNotificationStateAsync(int? tenantId, Guid userNotificationId, UserNotificationState state)
  42. {
  43. return _store.UpdateUserNotificationStateAsync(tenantId, userNotificationId, state);
  44. }
  45. public Task UpdateAllUserNotificationStatesAsync(UserIdentifier user, UserNotificationState state)
  46. {
  47. return _store.UpdateAllUserNotificationStatesAsync(user, state);
  48. }
  49. public Task DeleteUserNotificationAsync(int? tenantId, Guid userNotificationId)
  50. {
  51. return _store.DeleteUserNotificationAsync(tenantId, userNotificationId);
  52. }
  53. public Task DeleteAllUserNotificationsAsync(UserIdentifier user)
  54. {
  55. return _store.DeleteAllUserNotificationsAsync(user);
  56. }
  57. }
  58. }