Ejemplo n.º 1
0
        public async Task <IActionResult> SendNotificationForSubscribers(SubscribersNotificationDTO data)
        {
            if (ModelState.IsValid)
            {
                await notificationService.NotifySubscribers(data);

                await unitOfWork.SaveChanges();

                return(RedirectToAction(nameof(GetAllNotifications)));
            }
            return(Conflict(ModelState));
        }
Ejemplo n.º 2
0
        public async Task NotifySubscribers(SubscribersNotificationDTO subscribersNotification)
        {
            var notification = new Notification();

            var service = await serviceRepository.GetById(subscribersNotification.ServiceSenderId);

            notification.Text = subscribersNotification.Text;

            notification.Sender = service;

            foreach (var pair in service.SubscriptionSubscribers)
            {
                notification.Time       = DateTime.UtcNow;
                notification.ReceiverId = pair.SubscriberId;

                pair.Subscriber.Notifications.Add(notification);
                service.Notifications.Add(notification);

                await notificationRepository.Create(notification);
            }
        }