示例#1
0
        async Task CheckEventNotifications()
        {
            var events = await EventDataService.GetEvents();

            foreach (var eventModel in events)
            {
                var eventNotifications = await EventNotificationDataService.GetEventNotificationsById(eventModel.Id);

                var timeElapsed = Period.Between(LocalDateTime.FromDateTime(eventModel.EventDate), LocalDateTime.FromDateTime(DateTime.Now));
                var months      = timeElapsed.Years * 12 + timeElapsed.Months;

                //check if months equals any of monthly anniversaries or is a yearly anniv
                if (hardCodedAnniversaries.Contains(months) || (months != 0 && months % 12 == 0))
                {
                    var hasBeenSent = eventNotifications.Where(x => x.MonthQuantifier == months);

                    //no notification has been sent
                    if (hasBeenSent.Count() < 1)
                    {
                        await _notificationManager.Send("Congratulations!", $"It has been {months} months for {eventModel.Name}!");

                        await EventNotificationDataService.AddEventNotification(new Models.EventNotification {
                            EventId = eventModel.Id, MonthQuantifier = months
                        });
                    }
                }
            }
        }