Exemplo n.º 1
0
        public void SendNotifications(IMessageService messageService, INotifyService notifyService, TimeSpan timeSpan)
        {
            var messages      = messageService.GetNewerThan(DateTime.Now - timeSpan);
            var notifications = new List <Notification>();

            foreach (var message in messages)
            {
                var recipients = new List <string>();
                message.Receivers.ForEach(r => recipients.Add(r.Email));
                message.CC.ForEach(cc => recipients.Add(cc.Email));
                message.BCC.ForEach(bcc => recipients.Add(bcc.Email));

                var content = new NotificationContent()
                {
                    Sender  = message.Sender.Email,
                    Subject = message.Subject,
                    Body    = message.MessageBody
                };

                notifications.AddRange(recipients.Select(r => new Notification()
                {
                    Content        = JsonConvert.SerializeObject(content),
                    ContentType    = "application/json",
                    RecipientsList = new List <string> {
                        r
                    },
                    WithAttachments = message.Attachments.Any()
                }));
            }

            notifyService.SendNotifications(notifications);
            notifyService.UpdateConfig();
        }