public int SendApportionmentEmails([FromBody] UserApportionmentReportOptions options) { if (options == null) { throw new ArgumentNullException("options"); } var result = Provider.Billing.Report.SendUserApportionmentReport(options); return(result.TotalEmailsSent); }
public void CanViewApportionmentEmails() { var controller = new ReportController(); var opts = new UserApportionmentReportOptions { Period = DateTime.Parse("2019-03-01"), Message = "Please note: Due to a system issue this email was sent two days late. Please try to apportion your room charges today if possible. If you cannot, please let Sandrine ([email protected]) know and she can do this for you.", NoEmail = false }; var emails = controller.GetUserApportionmentReportEmails(opts); Assert.AreEqual(76, emails.Count()); Assert.AreEqual("*****@*****.**", emails.First().FromAddress); Assert.AreEqual("*****@*****.**", emails.First().CcAddress.First()); Assert.IsTrue(emails.First().Body.Contains(opts.Message)); }
public IEnumerable <ReportEmail> GetUserApportionmentReportEmails([FromBody] UserApportionmentReportOptions options) { using (DA.StartUnitOfWork()) return(ServiceProvider.Current.Billing.Report.GetUserApportionmentReportEmails(options)); }
public SendMonthlyApportionmentEmailsProcessResult SendUserApportionmentReport([FromBody] UserApportionmentReportOptions options) { using (DA.StartUnitOfWork()) return(ServiceProvider.Current.Billing.Report.SendUserApportionmentReport(options)); }
public IEnumerable <UserApportionmentReportEmail> GetUserApportionmentReportEmails(UserApportionmentReportOptions options) { return(Post <List <UserApportionmentReportEmail> >("webapi/billing/report/user-apportionment/view", options)); }
public SendMonthlyApportionmentEmailsProcessResult SendUserApportionmentReport(UserApportionmentReportOptions options) { return(Post <SendMonthlyApportionmentEmailsProcessResult>("webapi/billing/report/user-apportionment", options)); }
public SendMonthlyApportionmentEmailsProcessResult SendUserApportionmentReport(UserApportionmentReportOptions options) { var startedAt = DateTime.Now; var data = new List <string>(); //With noEmail set to true, nothing happens here. The appropriate users are selected and logged //but no email is actually sent. This is for testing/debugging purposes. var emails = GetUserApportionmentReportEmails(options); var apportionmentClientCount = emails.Count(); var totalEmailsSent = 0; foreach (var e in emails) { if (e.ToAddress.Length > 0) { if (!options.NoEmail) { SendEmail.Send(0, "LNF.Impl.Billing.Report.ReportRepository.SendUserApportionmentReport", e.Subject, e.Body, e.FromAddress, e.ToAddress, e.CcAddress, e.BccAddress, e.IsHtml); } // Always increment result even if noEmail == true so we can at least return how many emails would be sent. // Note this is not incremented unless an email was found for the user, even when there are recipients included. totalEmailsSent += 1; data.Add($"Needs apportionment: {string.Join(",", e.ToAddress)}"); } else { data.Add($"Needs apportionment: no email found for {e.DisplayName}"); } } var result = new SendMonthlyApportionmentEmailsProcessResult(startedAt, data) { ApportionmentClientCount = apportionmentClientCount, TotalEmailsSent = totalEmailsSent }; return(result); }
public IEnumerable <UserApportionmentReportEmail> GetUserApportionmentReportEmails(UserApportionmentReportOptions options) { var result = new List <UserApportionmentReportEmail>(); string[] ccAddr = GetApportionmentReminderRecipients(); var query = Apportionment.SelectApportionmentClients(options.Period, options.Period.AddMonths(1)); var tpl = GetTemplate("user-apportionment-email.handlebars"); var companyName = GlobalSettings.Current.CompanyName; var message = options.Message; var subj = $"Please apportion your {companyName} lab usage time"; foreach (IApportionmentClient ac in query) { var displayName = ac.DisplayName; var body = tpl(new { companyName, message, displayName }); var toAddr = ac.Emails.Split(','); result.Add(new UserApportionmentReportEmail { ClientID = ac.ClientID, DisplayName = ac.DisplayName, FromAddress = "*****@*****.**", ToAddress = toAddr, CcAddress = ccAddr, Subject = subj, Body = body, IsHtml = true }); } return(result); }