public void SaveMonitoredWebsite(MonitoredWebsite website)
        {
            MonitoredWebsitesCollection.Collection.Save(website);
            var notificationsDAL = new NotificationsDAL();

            var notification = new MonitoredWebsiteNotification
                                                            {
                                                                NotificationType =
                                                                    NotificationTypes.MonitoredWebsitesNotification,
                                                                WebsiteId = website.Id,
                                                                SentDate = DateTime.Now,
                                                                Title =
                                                                    String.Format(
                                                                        "Website at {0} has changed its content.",
                                                                        website.Id)
                                                            };

            notificationsDAL.InsertNotification(notification);

            var usersDAL = new UsersDAL();
            var allStudents = usersDAL.GetAllStudents();

            if (allStudents != null)
                foreach (var student in allStudents)
                {
                    if (student.SubscribedWebsites.Find(delegate(string gr)
                                                            {
                                                                return gr == website.Id;
                                                            }

                    ).Any())
                    {
                        student.Notifications.Add(new UserNotification
                        {
                            NotificationId = notification._id.ToString(),
                            NotificationType = NotificationTypes.MonitoredWebsitesNotification,
                            UserSolved = false
                        });
                    }
                    usersDAL.SaveStudent(student);
                }
        }
Beispiel #2
0
        public void InsertFeed(Feed feed)
        {
            FeedsCollection.Collection.Insert<Feed>(feed);

            var notificationsDAL = new NotificationsDAL();
            var notification = new FeedNotification
                                   {
                                       FeedId = feed._id.ToString(),
                                       NotificationType = NotificationTypes.FeedNotification,
                                       SentDate = DateTime.Now,
                                       Title = String.Format("{0} has posted a message.", feed.Sender)
                                   };
            notificationsDAL.InsertNotification(notification);

            var usersDAL = new UsersDAL();
            var allStudents = usersDAL.GetAllStudents();

                if (allStudents != null)
                    foreach (var student in allStudents)
                    {
                        if(student.SubscribedGroups.Find(delegate(string gr)
                                                             {
                                                                 foreach (var receiverGroup in feed.ReceiverGroups)
                                                                 {
                                                                     if (gr == receiverGroup)
                                                                         return true;
                                                                 }
                                                                 return false;
                                                             }

                        ).Any())
                        {
                            student.Notifications.Add(new UserNotification
                                                          {
                                                              NotificationId = notification._id.ToString(),
                                                              NotificationType = NotificationTypes.FeedNotification,
                                                              UserSolved = false
                                                          });
                        }
                        usersDAL.SaveStudent(student);
                    }
        }