Пример #1
0
        private async Task RemindAboutMeetings()
        {
            var meetingsToRemind = context.Meetings.Where(m => m.DateFrom <= DateTime.Now.AddDays(1) && m.Accepted && !m.Reminded);

            var userIds = meetingsToRemind.Select(m => new { m.UserId, m.School.OwnerId });

            userIds.ToList().ForEach(ui =>
            {
                var meeting = meetingsToRemind.FirstOrDefault(m => m.UserId == ui.UserId && m.School.OwnerId == ui.OwnerId);
                meeting.Remind();

                notificationSystem.PushNotification(ui.UserId, StaticExpressions.MeetingRemind(meeting.School.Name, meeting.DateFrom.ToShortDateString())).Wait();
                notificationSystem.PushNotification(ui.OwnerId, StaticExpressions.MeetingRemindForOwner(meeting.DateFrom.ToShortDateString())).Wait();
            });

            await context.SaveChangesAsync();
        }