Skip to content

Commit

Permalink
Merge pull request #116 from sebader/dev
Browse files Browse the repository at this point in the history
Notification email fixes
  • Loading branch information
sebader authored Sep 25, 2023
2 parents 8ef6287 + 7a1dc73 commit f793776
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions FetchDataFunctions/UpdateAvailabilityFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,20 +271,23 @@ public async Task<int> UpdateHutAvailability(
}
dbContext.RemoveRange(obsoleteExistingAva);

var subscriptionsOnDate = freeBedSubscriptions.Where(f => f.Date == day.Date);
foreach(var subscription in subscriptionsOnDate)
if (!day.HutClosed && day.Rooms.Any(r => r.FreeRoom > 0))
{
log.LogInformation("Sending free bed notification email for hut {hutId} on date {date}", hutId, day.Date);
var message = new SendGridMessage();
message.AddTo(subscription.EmailAddress);
message.AddContent("text/html", $"Es gibt wieder freie Plätze in {hut.Name} am {day.Date?.ToString("dd.MM.yyyy")}!<br /><br />Schaue direkt nach: <a href=\"{hut.Link}\">Online Buchung</a><br /><br />---<br />Gesendet von <a href=\"https://alpinehuts.silenced.eu\">alpinehuts.silenced.eu</a><br /><br /><%asm_preferences_raw_url%>");
message.SetFrom(new EmailAddress(Environment.GetEnvironmentVariable("EMAIL_SENDER_ADDRESS"), "Alpine Huts"));
message.SetSubject($"Freie Plätze in {hut.Name}!");
var subscriptionsOnDate = freeBedSubscriptions.Where(f => f.Date == day.Date);
foreach (var subscription in subscriptionsOnDate)
{
log.LogInformation("Sending free bed notification email for hut {hutId} on date {date}", hutId, day.Date);
var message = new SendGridMessage();
message.AddTo(subscription.EmailAddress);
message.AddContent("text/html", $"Es gibt wieder freie Plätze in {hut.Name} am {day.Date?.ToString("dd.MM.yyyy")}!<br /><br />Schaue direkt nach: <a href=\"{hut.Link}\">Online Buchung</a><br /><br />---<br />Gesendet von <a href=\"https://alpinehuts.silenced.eu\">alpinehuts.silenced.eu</a><br /><br />");
message.SetFrom(new EmailAddress(Environment.GetEnvironmentVariable("EMAIL_SENDER_ADDRESS"), "Alpine Huts"));
message.SetSubject($"Freie Plätze in {hut.Name}!");

await messageCollector.AddAsync(message);
await messageCollector.FlushAsync();
await messageCollector.AddAsync(message);
await messageCollector.FlushAsync();

subscription.Notified = true;
subscription.Notified = true;
}
}

numRowsWritten += await dbContext.SaveChangesAsync();
Expand Down

0 comments on commit f793776

Please sign in to comment.