Пример #1
0
        public async Task <IActionResult> Add([FromBody] VmSubscription sub)
        {
            if (!dc.Table <Subscription>().Any(x => x.Email == sub.Email.ToLower()))
            {
                dc.DbTran(() =>
                {
                    dc.Table <Subscription>().Add(new Subscription()
                    {
                        Email    = sub.Email.ToLower(),
                        IsActive = true
                    });
                });

                EmailRequestModel model = new EmailRequestModel();

                model.Subject     = Database.Configuration.GetSection("UserSubscriptionEmail:Subject").Value;
                model.ToAddresses = sub.Email;
                model.Template    = Database.Configuration.GetSection("UserSubscriptionEmail:Template").Value;

                if (engine == null)
                {
                    engine = new RazorLightEngineBuilder()
                             .UseFilesystemProject(Database.ContentRootPath + "\\App_Data")
                             .UseMemoryCachingProvider()
                             .Build();
                }

                var cacheResult = engine.TemplateCache.RetrieveTemplate(model.Template);

                var emailModel = new { Host = Database.Configuration.GetSection("clientHost").Value, Email = sub.Email };

                if (cacheResult.Success)
                {
                    model.Body = await engine.RenderTemplateAsync(cacheResult.Template.TemplatePageFactory(), emailModel);
                }
                else
                {
                    model.Body = await engine.CompileRenderAsync(model.Template, emailModel);
                }

                var    ses     = new AwsSesHelper(Database.Configuration);
                string emailId = await ses.Send(model, Database.Configuration);
            }

            return(Ok());
        }
Пример #2
0
        public async Task SendNotification(TbAirdrop data)
        {
            var config = Database.Configuration;
            EmailRequestModel model = new EmailRequestModel();

            model.Subject     = config.GetSection("JoinCandyProgramChinese:Subject").Value;
            model.ToAddresses = data.Email;
            model.Template    = config.GetSection("JoinCandyProgramChinese:Template").Value;

            if (!String.IsNullOrEmpty(model.Template))
            {
                if (engine == null)
                {
                    engine = new RazorLightEngineBuilder()
                             .UseFilesystemProject(Database.ContentRootPath + $"{Path.DirectorySeparatorChar}App_Data")
                             .UseMemoryCachingProvider()
                             .Build();
                }

                var cacheResult = engine.TemplateCache.RetrieveTemplate(model.Template);

                var emailModel = new { Host = config.GetSection("clientHost").Value, ActivationCode = data.ActivationCode };

                if (cacheResult.Success)
                {
                    model.Body = await engine.RenderTemplateAsync(cacheResult.Template.TemplatePageFactory(), emailModel);
                }
                else
                {
                    model.Body = await engine.CompileRenderAsync(model.Template, emailModel);
                }
            }

            var    ses     = new AwsSesHelper(config);
            string emailId = await ses.Send(model, config);

            $"join candy program user {data.Email}, user id: {data.Id}, sent email: {emailId}.".Log(LogLevel.INFO);
        }