99
1010namespace SimpleToDoService . Common
1111{
12- public class PushNotificationHelper
12+ public class PushNotificationScheduler
1313 {
1414 private readonly IToDoRepository repository ;
1515
16- public PushNotificationHelper ( IToDoRepository repository )
16+ public PushNotificationScheduler ( IToDoRepository repository )
1717 {
1818 this . repository = repository ;
1919 }
2020
2121 public async System . Threading . Tasks . Task SchedulePushNotification ( Task task )
2222 {
23- var currentNotification = task . PushNotifications . FirstOrDefault ( ) ; //repository.PushNotifications(task).FirstOrDefault();
23+ var currentNotification = task . PushNotifications . FirstOrDefault ( ) ;
24+
25+ if ( currentNotification ? . DueDate == task . CheckedTargetDate ( ) )
26+ return ;
27+
2428 DeletePushNotification ( currentNotification ) ;
2529 await CreatePushNotification ( task ) ;
2630 }
@@ -33,7 +37,7 @@ void DeletePushNotification(PushNotification notification)
3337
3438 async System . Threading . Tasks . Task CreatePushNotification ( Task task )
3539 {
36- var notificationDate = TaskDate ( task ) ;
40+ var notificationDate = task . CheckedTargetDate ( ) ;
3741 if ( ! notificationDate . HasValue )
3842 return ;
3943
@@ -90,18 +94,5 @@ async System.Threading.Tasks.Task CreatePushNotification(Task task)
9094 catch { }
9195#endif
9296 }
93-
94- private static DateTime ? TaskDate ( Task task )
95- {
96- if ( ! task . TargetDate . HasValue )
97- return null ;
98-
99- var notificationDate = task . TargetDate . Value . ToUniversalTime ( ) ;
100-
101- if ( ! task . TargetDateIncludeTime )
102- return new DateTime ( notificationDate . Year , notificationDate . Month , notificationDate . Day , 0 , 0 , 0 , notificationDate . Kind ) ;
103-
104- return task . TargetDate ;
105- }
10697 }
10798}
0 commit comments