public void AssignCourseUpdatedNotification(CourseUpdatedNotification notification, out Dictionary <string, List <int> > affectedUsersIds) { affectedUsersIds = new Dictionary <string, List <int> >(); if (notification != null) { var attenderNotifications = ( from attender in _context.CoursesAttenders where attender.CourseId == notification.CourseId select attender.AttenderId ).ToList <string>().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); } } } }
public void AddCourseUpdatedNotificationDetails(CourseUpdatedNotification notification, List <CourseUpdateToken> tokens) { if (notification != null) { var details = ( from token in tokens select new NotificationDetail(notification.Id, token.PropertyName, token.OldValue, token.NewValue) ).ToList(); if (details != null && details.Count > 0) { foreach (var detail in details) { notification.NotificationDetails.Add(detail); } } } }
private void CoursesAntenna_CourseUpdated(Course course, List <CourseUpdateToken> tokens) { if (course != null) { CourseUpdatedNotification notification = unitOfWork.NotificationsRepository.AddCourseUpdatedNotification(course, ContextHelpers.CurrentLoggedInUser.Id); unitOfWork.Complete(); if (tokens != null && tokens.Count > 0) { unitOfWork.NotificationsRepository.AddCourseUpdatedNotificationDetails(notification, tokens); unitOfWork.Complete(); } Dictionary <string, List <int> > affectedUsersIds = null; unitOfWork.NotificationsRepository.AssignCourseUpdatedNotification(notification, out affectedUsersIds); unitOfWork.Complete(); if (affectedUsersIds != null && affectedUsersIds.Count > 0) { NotifyUsers(affectedUsersIds); } } }
public CourseUpdatedNotification AddCourseUpdatedNotification(Course course, string userId) { CourseUpdatedNotification notification = new CourseUpdatedNotification(null, course.Id, null, userId); return(_context.CourseUpdatedNotifications.Add(notification)); }