/// <summary> /// Marks the notifications delivered asynchronously. /// </summary> /// <param name="deliveryChannel">The value from <see cref="NotificationDeliveryChannel"/> enum.</param> /// <param name="notifications">The notifications.</param> /// <returns>The instance of <see cref="Task"/> representing an asynchronous operation.</returns> private async Task MarkNotificationsDeliveredInternalAsync(NotificationDeliveryChannel deliveryChannel, IEnumerable <WebNotificationItemEntity> notifications) { Debug.Assert(notifications?.Any() ?? false, "Missing notifications."); List <WebNotificationItemEntity> webNotificationItemEntities = new List <WebNotificationItemEntity>(); foreach (var notificationItemEntity in notifications) { if (!notificationItemEntity.DeliveredOnChannel[deliveryChannel]) { notificationItemEntity.DeliveredOnChannel[deliveryChannel] = true; webNotificationItemEntities.Add(notificationItemEntity); } } _ = await this.notificationsRepository.UpsertAsync(webNotificationItemEntities).ConfigureAwait(false); }
/// <inheritdoc cref="INotificationDelivery"/> public async Task MarkNotificationDeliveredAsync(IEnumerable <string> notificationIds, NotificationDeliveryChannel deliveryChannel, bool throwExceptions = true) { EntityCollection <WebNotificationItemEntity> notificationCollection; this.logger.TraceInformation($"Started {nameof(this.MarkNotificationDeliveredAsync)} method of {nameof(NotificationsManager)}."); if (throwExceptions && notificationIds == null) { throw new ArgumentNullException(nameof(notificationIds)); } else if (notificationIds != null) { if (!notificationIds.Any()) { this.logger.TraceWarning("There are no notifications to mark delivered."); } else { notificationCollection = await this.LoadNotificationsWithIdsInternalAsync(notificationIds).ConfigureAwait(false); if (notificationCollection.Items != null) { await this.MarkNotificationsDeliveredInternalAsync(deliveryChannel, notificationCollection.Items).ConfigureAwait(false); } else { this.logger.TraceWarning($"There are no notifications located with identifier(s) '{string.Join(',', notificationIds.ToArray())}'"); } } } this.logger.TraceInformation($"Finished {nameof(this.MarkNotificationDeliveredAsync)} method of {nameof(NotificationsManager)}."); }