public static void NotifyOfMembersSpecialDates(string userEmail) { using (var unitOfWork = new UnitOfWork()) { var calService = new CalendarService(unitOfWork); var specialOccasions = calService.GetEventsForDateRange(DateTime.Now, DateTime.Now.AddDays(2), userEmail); if (specialOccasions == null || specialOccasions.Count() == 0) { return; } // Repository for sent notifications var notifyRepo = new NotificationsRepository(sentNotifications: true); var sentNotifications = notifyRepo.GetNotificationsByUserId(userEmail).ToList(); string message = string.Empty; foreach (var specialOccasion in specialOccasions) { message = $"{specialOccasion.Description} is on {specialOccasion.DateString}"; // To prevent user getting the same special occasion notifications multiple times if (!HasNotificationBeenSent(sentNotifications, specialOccasion.Title, message)) { SendUserNotification(userEmail, specialOccasion.Title, message, specialOccasion.Url, specialOccasion.Title, // link text type: NotificationType.Info); AddSentNotification(userEmail, specialOccasion.Title, message); } } // Get rid of old sent notifications after a set time span RemoveOldSentNotifications(userEmail, sentNotifications, notifyRepo); } }