File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,14 +25,25 @@ public async System.Threading.Tasks.Task SchedulePushNotification(Task task)
2525 if ( currentNotification ? . DueDate == task . CheckedTargetDate ( ) )
2626 return ;
2727
28- DeletePushNotification ( currentNotification ) ;
28+ await DeletePushNotification ( currentNotification ) ;
2929 await CreatePushNotification ( task ) ;
3030 }
3131
32- void DeletePushNotification ( PushNotification notification )
32+ async System . Threading . Tasks . Task DeletePushNotification ( PushNotification notification )
3333 {
3434 if ( notification == null )
3535 return ;
36+
37+ var url = String . Format ( "https://onesignal.com/api/v1/notifications/{0}?app_id={1}" ,
38+ notification . ServiceId . ToString ( ) , Environment . GetEnvironmentVariable ( "ONE_SIGNAL_KEY" ) ) ;
39+ var request = WebRequest . Create ( url ) as HttpWebRequest ;
40+
41+ request . Method = "DELETE" ;
42+ request . Headers [ "authorization" ] = String . Format ( "Basic {0}" , Environment . GetEnvironmentVariable ( "ONE_SIGNAL_KEY" ) ) ;
43+
44+ await request . GetResponseAsync ( ) ;
45+
46+ repository . DeletePushNotification ( notification ) ;
3647 }
3748
3849 async System . Threading . Tasks . Task CreatePushNotification ( Task task )
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ public interface IToDoRepository
2121 User UpdateUser ( User user ) ;
2222 PushNotification CreatePushNotification ( PushNotification notification ) ;
2323 IEnumerable < PushNotification > PushNotifications ( Task task ) ;
24+ bool DeletePushNotification ( PushNotification notification ) ;
2425 }
2526
2627 public class ToDoRepository : IToDoRepository
@@ -148,5 +149,21 @@ public IEnumerable<PushNotification> PushNotifications(Task task)
148149 return context . PushNotifications . Where ( o => o . TaskUuid == task . Uuid ) ;
149150
150151 }
152+
153+ public bool DeletePushNotification ( PushNotification notification )
154+ {
155+ context . PushNotifications . Remove ( notification ) ;
156+
157+ try
158+ {
159+ context . SaveChanges ( ) ;
160+ }
161+ catch
162+ {
163+ return false ;
164+ }
165+
166+ return true ;
167+ }
151168 }
152169}
You can’t perform that action at this time.
0 commit comments