public Task Execute(IJobExecutionContext context) { return(Task.Run(() => { try { var newEpisodes = new EpisodeStore().FindNewEpisodes(); if (newEpisodes.Count == 0) { return; } var details = new PushNotificationDetails { Title = NewInformationTodayTitle, Content = string.Join("\n", newEpisodes.Select(episode => $"{episode.ShowName} - {episode.Season}x{episode.EpisodeInSeason} - {episode.Title}")), TypeName = nameof(ThisJustInJob), AlertNumber = newEpisodes.Count }; _pushNotificationSender.NotifyAll(details); } catch (Exception exception) { Log.Error(exception, "Failed during This Just in Job"); } })); }
public Task Execute(IJobExecutionContext context) { return(Task.Run(() => { try { var episodes = new EpisodeStore().FindEpisodesAiring(DateTime.Today, DateTime.Today); if (episodes.Count == 0) { return; } var details = new PushNotificationDetails { Title = $"Airing Today", Content = string.Join("\n", episodes.Select(episode => $"{episode.ShowName} - {episode.Season}x{episode.EpisodeInSeason} - {episode.Title}")), TypeName = nameof(TVReleasingTodayJob), AlertNumber = episodes.Count }; _pushNotificationSender.NotifyAll(details); } catch (Exception exception) { Log.Error(exception, "Failed during TV releasing today job"); } })); }
public async Task <ActionResult <Result> > SendNotification([FromBody] PushNotificationDetails detailsRequest) { var notification = await _notificationStore.CreateNotification(detailsRequest); _firebasePusnNotificationSender.NotifyAll(notification); return(Result.Successful); }
public async Task <Notification> CreateNotification(PushNotificationDetails details) { const string sql = @" INSERT INTO public.notification (sent_time, title, content, type_name) VALUES (@SentTime, @Title, @Content, @TypeName)" ; using (var connection = Database.CreateConnection()) { var notification = new Notification { Title = details.Title, Content = details.Content, SentTime = DateTime.Now, TypeName = details.TypeName }; await connection.ExecuteAsync(sql, notification); return(notification); } }