Beispiel #1
0
        private async Task sendToDatabase(List <MimeMessage> messages)
        {
            await using var context = new E_RadarDbContext();
            await context.Database.MigrateAsync();

            foreach (var message in messages)
            {
                if (!await context.Messages.AnyAsync(x => x.UniqueId == message.MessageId))
                {
                    Console.WriteLine($"Found new matching message {message.From}, {message.Subject}.");

                    var newMessage = new MessageModel()
                    {
                        CreatedTime                      = DateTime.UtcNow,
                        SentTime                         = DateTime.Parse(message.Date.ToString()),
                        Notified                         = false,
                        UniqueId                         = message.MessageId,
                        From                             = message.From != null?message.From?.ToString() : message.ReplyTo?.ToString(),
                                                 To      = message.To.ToString(),
                                                 Cc      = message.Cc?.ToString(),
                                                 Bcc     = message.Bcc?.ToString(),
                                                 Subject = message.Subject?.ToString(),
                                                 Body    = message.TextBody
                    };
                    await context.Messages.AddAsync(newMessage);

                    await context.SaveChangesAsync();
                }
            }
        }
Beispiel #2
0
        private async Task logSentNotification(MimeMessage message)
        {
            using (var context = new E_RadarDbContext())
            {
                var newSentMessage = new SentMessageModel()
                {
                    CreatedTime = DateTime.UtcNow,
                    SentTime    = DateTime.Parse(message.Date.ToString()),
                    UniqueId    = message.MessageId,
                    From        = message.From.ToString(),
                    To          = message.To.ToString(),
                    Subject     = message.Subject,
                    Body        = message.TextBody
                };

                await context.SentMessages.AddAsync(newSentMessage);

                await context.SaveChangesAsync();
            }
        }
Beispiel #3
0
 private async Task updateNotifiedMessage(MessageModel message, E_RadarDbContext context)
 {
     message.Notified = true;
     context.Update(message);
     await context.SaveChangesAsync();
 }