using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Abp.Dependency;
namespace Abp.Notifications
{
///
/// Implements .
///
public class UserNotificationManager : IUserNotificationManager, ISingletonDependency
{
private readonly INotificationStore _store;
///
/// Initializes a new instance of the class.
///
public UserNotificationManager(INotificationStore store)
{
_store = store;
}
public async Task> GetUserNotificationsAsync(UserIdentifier user, UserNotificationState? state = null, int skipCount = 0, int maxResultCount = int.MaxValue)
{
var userNotifications = await _store.GetUserNotificationsWithNotificationsAsync(user, state, skipCount, maxResultCount);
return userNotifications
.Select(un => un.ToUserNotification())
.ToList();
}
public Task GetUserNotificationCountAsync(UserIdentifier user, UserNotificationState? state = null)
{
return _store.GetUserNotificationCountAsync(user, state);
}
public async Task GetUserNotificationAsync(int? tenantId, Guid userNotificationId)
{
var userNotification = await _store.GetUserNotificationWithNotificationOrNullAsync(tenantId, userNotificationId);
if (userNotification == null)
{
return null;
}
return userNotification.ToUserNotification();
}
public Task UpdateUserNotificationStateAsync(int? tenantId, Guid userNotificationId, UserNotificationState state)
{
return _store.UpdateUserNotificationStateAsync(tenantId, userNotificationId, state);
}
public Task UpdateAllUserNotificationStatesAsync(UserIdentifier user, UserNotificationState state)
{
return _store.UpdateAllUserNotificationStatesAsync(user, state);
}
public Task DeleteUserNotificationAsync(int? tenantId, Guid userNotificationId)
{
return _store.DeleteUserNotificationAsync(tenantId, userNotificationId);
}
public Task DeleteAllUserNotificationsAsync(UserIdentifier user)
{
return _store.DeleteAllUserNotificationsAsync(user);
}
}
}