Example #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                // This lambda determines whether user consent for non-essential cookies is needed for a given request.
                options.CheckConsentNeeded    = context => true;
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });



            /* TRANSIENTS */
            services.AddTransient <IInscricaoService, InscricaoService>();
            services.AddTransient <IInscricaoRepository, InscricaoRepository>();


            /* SINGLETONS */
            var sendGridConfig = new AuthMessageSenderOptionsDTO();

            new ConfigureFromConfigurationOptions <AuthMessageSenderOptionsDTO>(
                Configuration.GetSection("SendGrid"))
            .Configure(sendGridConfig);
            services.AddSingleton(sendGridConfig);



            /* INICIA O MVC */
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            /* CONFIGURAÇÕES GERAIS */
            services.AddDistributedMemoryCache();
        }
Example #2
0
        public async Task <string> EnviaEmail([FromBody] ContatoDTO contato, [FromServices] AuthMessageSenderOptionsDTO sendgridConfigDTO)
        {
            if (!(contato.Nome.Equals(string.Empty) &&
                  contato.Assunto.Equals(string.Empty) &&
                  contato.Email.Equals(string.Empty) &&
                  contato.Mensagem.Equals(string.Empty)))
            {
                var client = new SendGridClient(sendgridConfigDTO.SendGridKey);

                var recipients = new List <EmailAddress>
                {
                    new EmailAddress("*****@*****.**", "Marcel Ogando"),
                    new EmailAddress("*****@*****.**", "Lucas Simões"),
                    new EmailAddress("*****@*****.**", "Willian Chan"),
                    new EmailAddress("*****@*****.**", "Anna Flávia"),
                    new EmailAddress("*****@*****.**", "Larissa Ferreira"),
                };


                bool         displayRecipients = false;
                EmailAddress emailCliente      = new EmailAddress()
                {
                    Email = contato.Email,
                    Name  = contato.Nome
                };
                var msgPronta = MailHelper.CreateSingleEmailToMultipleRecipients(emailCliente, recipients, contato.Assunto, contato.Mensagem, "", displayRecipients);
                var response  = await client.SendEmailAsync(msgPronta);

                return("Mensagem enviada! Entraremos em contato pelo email informado assim que possível :)");
            }
            else
            {
                return("Algo deu errado no envio da mensagem, por favor revise os campos de mensagem e tente novamente :(");
            }
        }