public async Task<HttpResponseMessage> Post([FromBody]RfidEvents rfidEvents) { this.currentClub = this.ValidateRequest(); this.bsCache = BookedSchedulerCache.Instance[this.currentClub.Id]; this.telemetryClient = new TelemetryClient(); if (rfidEvents == null) { return new HttpResponseMessage(HttpStatusCode.BadRequest); } foreach (var ev in rfidEvents.Events) { if (!await this.bsCache.IsEventRedundantAsync(ev)) { await this.ProcessEvent(ev); } } return new HttpResponseMessage(HttpStatusCode.OK); }
/// <summary> /// Sends the generated report. /// </summary> /// <param name="log">The writer for logging.</param> /// <param name="clubInfo">Info about the club of interest</param> /// <param name="subject">The email subject</param> /// <param name="body">The email body</param> /// <returns>A task that completes when the email has been sent.</returns> private static async Task SendDailyReportEmail(TextWriter log, ClubInfo clubInfo, string subject, string body) { dynamic sg = new SendGridAPIClient(EnvironmentDefinition.Instance.SendGridApiKey); Email from = new Email(clubInfo.DailyReportSender); Content content = new Content("text/html", body); string[] recipients = new string[0]; if (EnvironmentDefinition.Instance.IsDevelopment) { recipients = new string[] { CloudConfigurationManager.GetSetting("DeveloperEmail", false) }; } else if (EnvironmentDefinition.Instance.IsProduction) { recipients = clubInfo.DailyReportRecipients.Split(','); } foreach (var recipient in recipients) { try { Email to = new Email(recipient); Mail mail = new Mail(from, subject, to, content); dynamic response = await sg.client.mail.send.post(requestBody: mail.Get()); log.WriteLine($"Sent report email to {recipient}"); } catch (Exception ex) { log.WriteLine($"Failed to send report email to {recipient}: {ex.Message}"); } } }