Ejemplo n.º 1
0
        // public List<Feed> GetFeedsForGroup(string facultyId, string groupId)
        // {
        //     List<Feed> list = null;
        //     var usersDAL = new UsersDAL();
        //     usersDAL.GetGroupsByFaculty(facultyId);
        //     if (group.YearOfStudy != StudyYear.None)
        //     {
        //         if (!String.IsNullOrEmpty(group.Number))
        //         {
        //             if ((group.HalfYearOfStudy == HalfYear.None &&
        //                 (group.YearOfStudy != StudyYear.I1 || group.YearOfStudy != StudyYear.I2 || group.YearOfStudy != StudyYear.I3)) || // masters or bachelors
        //
        //                 (group.HalfYearOfStudy != HalfYear.None &&
        //                 (group.YearOfStudy == StudyYear.I1 || group.YearOfStudy == StudyYear.I2 || group.YearOfStudy == StudyYear.I3)))
        //             {
        //                 list = GetFeedsForFullGroup(group);
        //             }
        //         }
        //         else
        //             if (group.HalfYearOfStudy != HalfYear.None)
        //             {
        //                 list = GetFeedsForHalfYear(group.YearOfStudy, group.HalfYearOfStudy);
        //             }
        //             else
        //                 list = GetFeedsForYear(group.YearOfStudy);
        //     }
        //     return list;
        // }
        //
        // private List<Feed> GetFeedsForYear(StudyYear yearOfStudy)
        // {
        //     var yearQuery = Query.EQ("ReceiverGroups.YearOfStudy", yearOfStudy);
        //     return FeedsCollection.Collection.FindAs<Feed>(yearQuery).ToList();
        // }
        //
        // private List<Feed> GetFeedsForHalfYear(StudyYear yearOfStudy, HalfYear halfYearOfStudy)
        // {
        //     var yearQuery = Query.EQ("ReceiverGroups.YearOfStudy", yearOfStudy);
        //     var halfYearQuery = Query.EQ("ReceiverGroups.HalfYearOfStudy", halfYearOfStudy);
        //     var fullQuery = Query.And(yearQuery, halfYearQuery);
        //
        //     return FeedsCollection.Collection.FindAs<Feed>(fullQuery).ToList();
        // }
        //
        // private List<Feed> GetFeedsForFullGroup(Group group)
        // {
        //     var yearQuery = Query.EQ("ReceiverGroups.YearOfStudy", group.YearOfStudy);
        //     var halfYearQuery = Query.EQ("ReceiverGroups.HalfYearOfStudy", group.HalfYearOfStudy);
        //     var groupQuery = Query.EQ("ReceiverGroups.Number", group.Number);
        //     var fullQuery = Query.And(yearQuery, halfYearQuery, groupQuery);
        //
        //     return FeedsCollection.Collection.FindAs<Feed>(fullQuery).ToList();
        // }
        public List<Feed> GetFeedsForGroup(string facultyId, string groupId)
        {
            var usersDAL = new UsersDAL();
            var feedsDAL = new FeedsDAL();
            var query = Query.EQ("ReceiverGroups.Id", groupId);

            return FeedsCollection.Collection.FindAs<Feed>(query).ToList();
        }
Ejemplo n.º 2
0
 public override bool IsUserInRole(string username, string roleName)
 {
     var usersDAL = new UsersDAL();
     var user = usersDAL.GetUser(username);
     if (user.Roles != null)
         return user.Roles.Any(role => role.Name == roleName);
     return false;
 }
Ejemplo n.º 3
0
        public string[] GetRolesForUser(string username)
        {
            var usersDAL = new UsersDAL();
            var user = usersDAL.GetUser(username);
            var list = new List<string>();

            if (user != null && user.Roles != null)
                list.AddRange(user.Roles.Select(role => role.Name));
            return list.ToArray();
        }
Ejemplo n.º 4
0
        public void AddUserToRole(string username, string roleName)
        {
            var usersDAL = new UsersDAL();
            var user = usersDAL.GetUser(username);

            if(user.Roles == null)
                user.Roles = new List<UserRole>();
            user.Roles.Add(new UserRole { Name= roleName, UserType = (UserTypes)Enum.Parse(typeof(UserTypes), roleName) });
            usersDAL.SaveUser(user);
        }
Ejemplo n.º 5
0
 public List<MonitoredWebsite> GetMonitoredWebsitesByUsername(string userName)
 {
     UsersDAL uDAL = new UsersDAL();
     List<string> siteLinks = uDAL.GetSubscribedWebsiteLinks(userName);
     List<MonitoredWebsite> siteList = new List<MonitoredWebsite>();
     foreach (var item in siteLinks)
     {
         MonitoredWebsite temp = MonitoredWebsitesCollection.Collection.FindOneByIdAs<MonitoredWebsite>(item);
         if (temp != null)
         {
             siteList.Add(temp);
         }
     }
     return siteList;
 }
Ejemplo n.º 6
0
        public List<MonitoredWebsite> GetAllMonitoredWebsites(string userName)
        {
            List<MonitoredWebsite> list = new List<MonitoredWebsite>();
            var usersDAL = new UsersDAL();
            var user = usersDAL.GetStudent(userName);

            if(user != null)
            {
                foreach(var item in user.SubscribedWebsites)
                {
                    MonitoredWebsite website = MonitoredWebsitesCollection.Collection.FindOneByIdAs<MonitoredWebsite>(item);
                    if (website != null)
                        list.Add(website);
                }
            }
            return list;
        }
Ejemplo n.º 7
0
 public string[] FindUsersInRole(string roleName, string usernameToMatch)
 {
     var usersDAL = new UsersDAL();
     var users = usersDAL.GetAllUsers();
     var listOfUsers = new List<string>();
     foreach (var user in users)
     {
         if(user.Name.Contains(usernameToMatch))
         {
             foreach (var role in user.Roles)
             {
                 if(role.Name == roleName)
                 {
                     listOfUsers.Add(user.Name);
                 }
             }
         }
     }
     return listOfUsers.ToArray();
 }
Ejemplo n.º 8
0
        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);
                }
        }
Ejemplo n.º 9
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);
                    }
        }
Ejemplo n.º 10
0
        public void RemoveUserFromRole(string username, string roleName)
        {
            var usersDAL = new UsersDAL();
            var user = usersDAL.GetUser(username);

            if (user.Roles == null)
                user.Roles = new List<UserRole>();
            int index = user.Roles.FindIndex(0, delegate(UserRole role)
                                        {
                                            return role.Name == roleName;
                                        });

            if(index < user.Roles.Count)
            user.Roles.RemoveAt(index);
            usersDAL.SaveUser(user);
        }
Ejemplo n.º 11
0
 public string[] GetUsersInRole(string roleName)
 {
     var usersDAL = new UsersDAL();
     var allUsers = usersDAL.GetAllUsers();
     var list = new List<string>();
     if (allUsers != null)
         foreach (var user in allUsers.Where(user => user.Roles != null))
         {
             list.AddRange(from role in user.Roles where role.Name == roleName select user.Id);
         }
     return list.ToArray();
 }