private dynamic GetTemplate(NotificationTemplateTypes notificationTemplateTypeId, string culture) { using (var dbContext = new MazzaDbContext()) { var cultureid = dbContext.Cultures.FirstOrDefault(c => c.Code.Equals(culture)); if (cultureid == null) { cultureid.Id = 1; } var template = dbContext.NotificationTemplates.FirstOrDefault(n => n.NotificationTypeId == (int)notificationTemplateTypeId && n.CultureId == 1); return(template); } }
public void SendEmailFromTemplate(NotificationTemplateTypes notificationTemplateTypeId, EmailEntity emailEntity) { string emailTo = string.Empty; var host = new RazorEngine <RazorTemplateBase>(); host.AddAssembly("System.Data.dll"); var template = GetTemplate(notificationTemplateTypeId, emailEntity.Culture); object razorContext = GetNotificationRazorContext(notificationTemplateTypeId, emailEntity, out emailTo); string compiledId = host.CompileTemplate(template.MessageTemplate); string message = host.RenderTemplateFromAssembly(compiledId, razorContext); Send(emailTo, template.Subject, message); }
private object GetNotificationRazorContext(NotificationTemplateTypes notificationTemplateTypes, EmailEntity emailEntity, out string emailTo) { object razorContext = null; emailTo = string.Empty; switch (notificationTemplateTypes) { case NotificationTemplateTypes.UserRegistration: emailTo = emailEntity.Affiliate.Email; razorContext = emailEntity; break; case NotificationTemplateTypes.NewAffiliateRegistration: emailTo = emailEntity.Referent.Email; razorContext = emailEntity; break; case NotificationTemplateTypes.ForgotPassword: emailTo = emailEntity.Affiliate.Email; razorContext = emailEntity; break; } return(razorContext); }