public static async Task <Email> GenerateAuditInspectionEmail(JobOrder.Model.JobOrder jobOrder, IEmailService emailService, Officer officer, EmailTemplateType templateType, string recipient) { var template = await emailService.GetTemplate(templateType); var ScheduledOn = jobOrder.ScheduledOn.Value.AddHours(8); var ScheduledOnTo = jobOrder.ScheduledOnTo.Value.AddHours(8); var email = new Email { From = template.From, To = recipient, Cc = template.Cc.Replace("{officerEmail}", officer?.Email ?? ""), Title = template.Title.Replace("{customer}", jobOrder.Customer.Name), Body = template.Body.Replace("{customer}", jobOrder.Customer.Name) .Replace("{premise}", PremiseUtil.format(jobOrder.Premises[0])) .Replace("{scheduledDate}", ScheduledOn.ToString("dd MMM yyyy")) .Replace("{startTime}", ScheduledOn.ToString("hh:mm tt")) .Replace("{endTime}", ScheduledOnTo.ToString("hh:mm tt")) .Replace("{officerName}", officer?.Name ?? ""), IsBodyHtml = template.IsBodyHtml }; return(email); }
public async Task SendEmail(DbContext dbContext, JobOrder.Model.JobOrder jobOrder) { if (jobOrder.Type != Model.JobOrderType.Audit) { return; } var emailID = (await dbContext.JobOrder.GetEmails(jobOrder.ID)).FirstOrDefault(); if (emailID == 0) { return; } var email = await _emailService.GetByID(emailID); email = await EmailHelper.GenerateAuditInspectionEmail(jobOrder, _emailService, _user, EmailTemplateType.RescheduleAuditInspection, email.To); email = await _emailService.Save(email); await dbContext.JobOrder.MapEmail(jobOrder.ID, email.ID); _smtpProvider.Send(new Mail { From = email.From, Recipients = email.To?.Split(";"), Cc = email.Cc?.Split(";"), Bcc = email.Bcc?.Split(";"), Subject = email.Title, Body = email.Body, IsBodyHtml = email.IsBodyHtml }); }
public async Task <Unit> Invoke(IUnitOfWork uow) { var dbContext = Repository.DbContext.From(uow); uow.BeginTransaction(); var schedulers = await dbContext.PeriodicScheduler.GetSchedulers(); foreach (PeriodicScheduler schedulerItem in schedulers) { var certificate = await dbContext.Certificate.Select(new Model.CertificateOptions { PremiseID = schedulerItem.PremiseID }); var jobOrder = new JobOrder.Model.JobOrder { Type = JobOrderType.Periodic, Status = JobOrderStatus.Draft, TargetDate = schedulerItem.NextTargetInspection, CustomerID = certificate.Customer.ID, Customer = new Customer { ID = certificate.Customer.ID, Name = certificate.Customer.Name, Code = certificate.Customer.Code }, LineItems = new List <JobOrder.Model.JobOrderLineItem> { new JobOrderLineItem { Scheme = certificate.Scheme, SubScheme = certificate.SubScheme } }, Premises = new List <Premise> { certificate.Premise } }; var jobId = await dbContext.JobOrder.InsertJobOrder(jobOrder); var logText = await dbContext.Translation.GetTranslation(Locale.EN, "JobOrderCreate"); var logID = await dbContext.Log.InsertLog(new Log { Type = LogType.JobOrder, Action = logText }); var scheduler = await dbContext.PeriodicScheduler.Select(new Model.PeriodicSchedulerOptions { PremiseID = certificate.Premise.ID }); await dbContext.PeriodicScheduler.InsertOrReplace(new PeriodicScheduler { PremiseID = certificate.Premise.ID, LastJobID = jobId, NextTargetInspection = scheduler[0].NextTargetInspection, LastScheduledOn = scheduler[0].LastScheduledOn, Status = scheduler[0].Status, }); _eventBus.Publish(new SendNotificationWithPermissionsEvent { Title = await dbContext.Translation.GetTranslation(Locale.EN, "PeriodicSchedulerTitle"), Body = await dbContext.Translation.GetTranslation(Locale.EN, "PeriodicSchedulerBody"), Module = "PeriodicInspection", RefID = $"{jobId}", Permissions = new List <Permission> { Permission.PeriodicInspectionReadWrite } }); } uow.Commit(); return(Unit.Default); }