public void AssignCourseCreatedNotification(CourseCreatedNotification notification, out Dictionary <string, List <int> > affectedUsersIds) { affectedUsersIds = new Dictionary <string, List <int> >(); if (notification != null) { var attenderNotifications = ( from attender in _context.CoursesAttenders.Distinct() select attender.AttenderId ).ToList <string>().Distinct().Select(id => new UserNotification(notification.Id, id)); if (attenderNotifications != null && attenderNotifications.Count() > 0) { _context.UserNotifications.AddRange(attenderNotifications); foreach (UserNotification un in attenderNotifications) { if (!affectedUsersIds.ContainsKey(un.UserId)) { affectedUsersIds.Add(un.UserId, new List <int>()); } affectedUsersIds[un.UserId].Add(un.NotificationId); } } } }
private void CoursesAntenna_CourseCreated(Course course) { if (course != null) { CourseCreatedNotification notification = unitOfWork.NotificationsRepository.AddCourseCreatedNotification(course, ContextHelpers.CurrentLoggedInUser.Id); unitOfWork.Complete(); Dictionary <string, List <int> > affectedUsersIds = null; unitOfWork.NotificationsRepository.AssignCourseCreatedNotification(notification, out affectedUsersIds); unitOfWork.Complete(); if (affectedUsersIds != null && affectedUsersIds.Count > 0) { NotifyUsers(affectedUsersIds); } } }