Exemplo n.º 1
0
        private DispatchNotificationResult SendNotificationsAndSetDispatchDate(IEnumerable <Notification> notifications)
        {
            var factory = new SenderFactory(_configuration, _logger, _smsService);
            var respone = new DispatchNotificationResult();

            foreach (var notification in notifications)
            {
                var message = _messageService.CreateMessage(notification);
                var sender  = new MessageSender(factory.CreateSenderObject(notification.MessageType), message);
                var result  = sender.Send();
                if (result)
                {
                    var dateOfDisptach = SystemTime.Now;
                    notification.DateOfLastDispatch = dateOfDisptach;
                    respone.sentNotifications.Add(Mapper.Map <NotificationDto>(notification));
                    message.DateOfSending = dateOfDisptach;
                    _messageService.AddMessage(message);
                    continue;
                }
                respone.notSentNotifications.Add(Mapper.Map <NotificationDto>(notification));
            }

            _notificationRepository.Save();

            return(respone);
        }