public static void NotifyNewComment(int commentId)
        {
            // Prepare Postal classes to work outside of ASP.NET request
            var viewsPath = Path.GetFullPath(HostingEnvironment.MapPath(@"~/Views/Emails"));
            var engines   = new ViewEngineCollection();

            engines.Add(new FileSystemRazorViewEngine(viewsPath));

            var emailService = new EmailService(engines);

            // Get comment and send a notification.
            using (var db = new MailerDbContext())
            {
                var comment = db.Comments.Find(commentId);

                var email = new NewCommentEmail
                {
                    To       = "*****@*****.**",
                    UserName = comment.UserName,
                    Comment  = comment.Text
                };

                emailService.Send(email);
            }
        }
Ejemplo n.º 2
0
        public void NotifyNewComment(int commentId)
        {
            // Prepare Postal classes to work outside of ASP.NET request
            var viewsPath = Path.GetFullPath(HostingEnvironment.MapPath(@"~/Views/Emails"));
            var engines   = new ViewEngineCollection();

            engines.Add(new FileSystemRazorViewEngine(viewsPath));

            var client = new SmtpClient()
            {
                Host                  = "smtp.sendgrid.net",
                Port                  = 587,
                EnableSsl             = true,
                UseDefaultCredentials = false,
                Credentials           =
                    new NetworkCredential("xpto", "xtpo")
            };
            var emailService = new EmailService(engines, () => client);

            // Get comment and send a notification.
            using (var db = new MailerDbContext())
            {
                var comment = db.Comments.Find(commentId);
                //var evento = db.tbClientesEventos.Where(c => c.cdEvento.Equals("010701"));

                var email = new NewCommentEmail
                {
                    To       = "*****@*****.**",
                    UserName = comment.UserName,
                    Comment  = comment.Text
                };

                emailService.Send(email);
            }
        }
Ejemplo n.º 3
0
        public static void NotifyNewComment(int commentId)
        {
            var currentCultureName = Thread.CurrentThread.CurrentCulture.Name;

            if (currentCultureName != "es-ES")
            {
                throw new InvalidOperationException(String.Format("Current culture is {0}", currentCultureName));
            }

            // Prepare Postal classes to work outside of ASP.NET request
            var viewsPath = Path.GetFullPath(HostingEnvironment.MapPath(@"~/Views/Emails"));
            var engines   = new ViewEngineCollection();

            engines.Add(new FileSystemRazorViewEngine(viewsPath));

            var emailService = new EmailService(engines);

            // Get comment and send a notification.
            using (var db = new MailerDbContext())
            {
                var comment = db.Comments.Find(commentId);

                var email = new NewCommentEmail
                {
                    To       = "*****@*****.**",
                    UserName = comment.UserName,
                    Comment  = comment.Text
                };

                emailService.Send(email);
            }
        }
Ejemplo n.º 4
0
        public static void NotifyNewComment(int commentId)
        {
            var currentCultureName = Thread.CurrentThread.CurrentCulture.Name;
            if (currentCultureName != "es-ES")
            {
                throw new InvalidOperationException(String.Format("Current culture is {0}", currentCultureName));
            }

            // Prepare Postal classes to work outside of ASP.NET request
            var viewsPath = Path.GetFullPath(HostingEnvironment.MapPath(@"~/Views/Emails"));
            var engines = new ViewEngineCollection();
            engines.Add(new FileSystemRazorViewEngine(viewsPath));

            var emailService = new EmailService(engines);

            // Get comment and send a notification.
            using (var db = new MailerDbContext())
            {
                var comment = db.Comments.Find(commentId);

                var email = new NewCommentEmail
                {
                    To = "*****@*****.**",
                    UserName = comment.UserName,
                    Comment = comment.Text
                };

                emailService.Send(email);
            }
        }
Ejemplo n.º 5
0
 public IHttpActionResult MailApiKeys()
 {
     using (var db = new MailerDbContext())
     {
         var apiKeys = db.ApiKeys.ToList();
         return(Ok(apiKeys));
     }
 }
Ejemplo n.º 6
0
 public IHttpActionResult MailAccounts()
 {
     using (var db = new MailerDbContext())
     {
         var accounts = db.MailAccounts.ToList();
         return(Ok(accounts));
     }
 }
Ejemplo n.º 7
0
 public MailCommandHandlers(
     MailerDbContext dbContext,
     IMailClient mailClient,
     IMailDomainValidator domainValidator)
 {
     _dbContext       = dbContext;
     _mailClient      = mailClient;
     _domainValidator = domainValidator;
 }
Ejemplo n.º 8
0
        public async Task <MailUser> GetUserAccount(int userId)
        {
            using (var db = new MailerDbContext())
            {
                var account = await db.Users
                              .FirstOrDefaultAsync(x => x.Id == userId);

                return(account.AsMailUser());
            }
        }
Ejemplo n.º 9
0
        private MailerDbContext SetupDb()
        {
            var options = new DbContextOptionsBuilder <MailerDbContext>()
                          .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
                          .Options;
            var databaseContext = new MailerDbContext(options);

            databaseContext.Database.EnsureCreated();

            return(databaseContext);
        }
Ejemplo n.º 10
0
        public void Configuration(IAppBuilder app)
        {
            MailerDbContext db = new MailerDbContext();
            
            GlobalConfiguration.Configuration
                .UseSqlServerStorage(
                    "MailerDbContext",
                    new SqlServerStorageOptions { QueuePollInterval = TimeSpan.FromSeconds(1) });

            app.UseHangfireDashboard();
            app.UseHangfireServer();
        }
Ejemplo n.º 11
0
        public ActionResult Index(ConfirmationEmailViewModel model)
        {
            if (model != null)
            {
                using (MailerDbContext db = new MailerDbContext())
                {
                    model.Id         = Guid.NewGuid();
                    model.QRCodePath = CreateQRCodeImage(model.Id.ToString());
                    db.ConfirmationEmails.Add(model);
                    db.SaveChanges();
                }

                BackgroundJob.Enqueue(() => SendConfirmationEmail(model.Id));
            }

            return(View());
        }
Ejemplo n.º 12
0
        public async Task <MailAccount> GetMailAccount(int accountId, bool includeUser = false)
        {
            using (var db = new MailerDbContext())
            {
                var query = db.MailAccounts
                            .Where(x => x.Id == accountId);

                if (includeUser)
                {
                    query = query.Include(x => x.User);
                }

                var account = await query.FirstOrDefaultAsync();

                return(account.AsMailAccount());
            }
        }
Ejemplo n.º 13
0
        public static void SendConfirmationEmail(Guid id)
        {
            var viewsPath = Path.GetFullPath(HostingEnvironment.MapPath(@"~/Views/Emails"));
            var engines   = new ViewEngineCollection();

            engines.Add(new FileSystemRazorViewEngine(viewsPath));

            var emailService = new EmailService(engines);

            using (var db = new MailerDbContext())
            {
                var m = db.ConfirmationEmails.Find(id);
                ConfirmationEmail em = new ConfirmationEmail();
                em.Name    = m.Name;
                em.Surname = m.Surname;
                em.To      = m.Email;
                em.Attachments.Add(new System.Net.Mail.Attachment(m.QRCodePath));
                emailService.Send(em);
            }
        }
Ejemplo n.º 14
0
 public AttachmentCommandHandler(MailerDbContext dbContext, IMailDomainValidator domainValidator)
 {
     _dbContext       = dbContext;
     _domainValidator = domainValidator;
 }
Ejemplo n.º 15
0
 protected BaseHandlersTests()
 {
     DbContext = SetupDb();
 }
Ejemplo n.º 16
0
 public MailQueryHandlers(MailerDbContext dbContext)
 {
     _dbContext = dbContext;
 }