public async Task <int> SendNotificationAsync(List <string> recipients, CcEvent template) { var notifications = CreateNotifications(recipients, template).ToList(); _notificationFlag.TouchIf(notifications.Count); if (notifications.Any()) { notifications.ForEach(i => _dbService.Events.Add(i)); // await _dbService.Events.InsertManyAsync(notifications); } return(notifications.Count); }
public async Task <long> MarkNotificationAsReadAsync(CcEvent ccEvent) { if (ccEvent != null) { var notifications = await _dbService.Events.FindAsync(i => i.Id == ccEvent.Id); var result = await _dbService.Events.MarkAsReadAsync(notifications); _notificationFlag.TouchIf(result); return(result); } return(0L); }
public IEnumerable <CcEvent> CreateNotifications(List <string> recipients, CcEvent template) { var sender = template.Sender; foreach (var recipient in recipients) { if (sender == recipient) { continue; } var copy = template.Clone(); copy.Reciever = recipient; yield return(copy); } }