コード例 #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));
        }
コード例 #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);
            }
        }