public async Task <DateTime?> GetLastDeliveryTimestampAsync(NotificationTransport notificationTransport) { var lastNotification = await db.NotificationDeliveries.Where(d => d.NotificationTransportId == notificationTransport.Id) .OrderByDescending(d => d.CreateTime) .FirstOrDefaultAsync(); return(lastNotification?.CreateTime); }
public DateTime?GetLastDeliveryTimestamp(NotificationTransport notificationTransport) { var lastNotification = db.NotificationDeliveries.Where(d => d.NotificationTransportId == notificationTransport.Id) .OrderByDescending(d => d.CreateTime) .FirstOrDefault(); return(lastNotification?.CreateTime); }
public async Task AddNotificationTransport(NotificationTransport transport) { DeleteOldNotificationTransports(transport.GetType(), transport.UserId); transport.IsDeleted = false; db.NotificationTransports.Add(transport); await db.SaveChangesAsync(); }
public async Task AddNotificationTransport(NotificationTransport transport) { using (var transaction = db.Database.BeginTransaction()) { await DeleteOldNotificationTransports(transport.GetType(), transport.UserId); transport.IsDeleted = false; db.NotificationTransports.Add(transport); await db.SaveChangesAsync(); await transaction.CommitAsync(); } }
public async Task SendDeliveriesOfOneType(NotificationTransport transport, NotificationType notificationType, List <NotificationDelivery> deliveries) { if (deliveries.Count == 0) { return; } if (deliveries.Count == 1) { var delivery = deliveries[0]; var course = courseManager.FindCourse(delivery.Notification.CourseId); if (course == null) { log.Warn($"Can't find course {delivery.Notification.CourseId}"); await notificationsRepo.MarkDeliveryAsFailed(delivery); return; } try { await notificationSender.SendAsync(delivery); await notificationsRepo.MarkDeliveryAsSent(delivery.Id); } catch (Exception e) { log.Warn($"Can\'t send notification {delivery.NotificationId} to {delivery.NotificationTransport}: {e}. Will try later"); await notificationsRepo.MarkDeliveryAsFailed(delivery); } } else { try { await notificationSender.SendAsync(deliveries); await notificationsRepo.MarkDeliveriesAsSent(deliveries.Select(d => d.Id).ToList()); } catch (Exception e) { log.Warn($"Can\'t send multiple notifications [{string.Join(", ", deliveries.Select(d => d.NotificationId))}] to {deliveries[0].NotificationTransport}: {e}. Will try later"); await notificationsRepo.MarkDeliveriesAsFailed(deliveries); } } }
public async Task AddNotificationTransport(NotificationTransport transport) { using (var transaction = db.Database.BeginTransaction()) { DeleteOldNotificationTransports(transport.GetType(), transport.UserId); /* * if (transport is MailNotificationTransport) * DeleteOldNotificationTransports<MailNotificationTransport>(transport.UserId); * if (transport is TelegramNotificationTransport) * DeleteOldNotificationTransports<TelegramNotificationTransport>(transport.UserId); */ transport.IsDeleted = false; db.NotificationTransports.Add(transport); await db.SaveChangesAsync().ConfigureAwait(false); transaction.Commit(); } }
public IQueryable <NotificationDelivery> GetTransportDeliveries(NotificationTransport notificationTransport, DateTime from) { return(db.NotificationDeliveries.Where(d => d.NotificationTransportId == notificationTransport.Id && d.CreateTime > from)); }