Exemple #1
0
        public void RemoveUser(Team team, User user)
        {
            Team teamDataBase = new Team();

            using (ContextDB context = new ContextDB())
            {
                context.Configuration.ProxyCreationEnabled = false;
                teamDataBase = context.Teams.Find(team.OIDTeam);
                List <User> users = context.Teams
                                    .Where(t => t.name == teamDataBase.name)
                                    .Include(t => t.usersInTeam)
                                    .FirstOrDefault()
                                    .usersInTeam.ToList();
                users.Remove(user);
                context.Teams
                .Where(t => t.name == teamDataBase.name)
                .Include(t => t.usersInTeam)
                .FirstOrDefault()
                .usersInTeam = users;
                context.SaveChanges();
            }
            if (teamDataBase.usersInTeam.Count == 0)
            {
                DeleteTeam(team);
            }
        }
Exemple #2
0
 public void AddAdministrator(Administrator administrator)
 {
     using (ContextDB context = new ContextDB())
     {
         context.Administrators.Add(administrator);
         context.SaveChanges();
     }
 }
Exemple #3
0
 public void AddColaborator(Colaborator colaborator)
 {
     using (ContextDB context = new ContextDB())
     {
         context.Colaborators.Add(colaborator);
         context.SaveChanges();
     }
 }
 public void AddBlackboard(Blackboard blackboard)
 {
     using (ContextDB context = new ContextDB())
     {
         context.Blackboards.Add(blackboard);
         context.SaveChanges();
     }
 }
Exemple #5
0
 public void AddComment(Comment comment)
 {
     using (ContextDB context = new ContextDB())
     {
         context.Comments.Add(comment);
         context.SaveChanges();
     }
 }
Exemple #6
0
 public void DeleteTeam(Team team)
 {
     using (ContextDB context = new ContextDB())
     {
         var query = context.Teams.Find(team.OIDTeam);
         context.Teams.Remove(query);
         context.SaveChanges();
     }
 }
Exemple #7
0
 public void ModifyTeamMaxUsers(string nameOfTeam, int newMaxUsers)
 {
     using (ContextDB context = new ContextDB())
     {
         context.Teams
         .Where(t => t.name == nameOfTeam)
         .FirstOrDefault().maxUsers = newMaxUsers;
         context.SaveChanges();
     }
 }
Exemple #8
0
        public List <Team> LoadTeams()
        {
            List <Team> allTeams = new List <Team>();

            using (ContextDB context = new ContextDB())
            {
                allTeams = context.Teams.ToList();
            }
            return(allTeams);
        }
Exemple #9
0
        public List <User> LoadUsers()
        {
            List <User> allUsers = new List <User>();

            using (ContextDB context = new ContextDB())
            {
                context.Configuration.ProxyCreationEnabled = false;
                allUsers = context.Users.ToList();
            }
            return(allUsers);
        }
Exemple #10
0
 public List <User> GetUsersFromTeam(Team team)
 {
     using (ContextDB context = new ContextDB())
     {
         List <User> query = context.Teams.Where(t => t.name == team.name)
                             .Include(t => t.usersInTeam)
                             .FirstOrDefault()
                             .usersInTeam.ToList();
         return(query);
     }
 }
Exemple #11
0
 public void ModifyTeamDescription(string nameOfTeam, string newDescription)
 {
     using (ContextDB context = new ContextDB())
     {
         context.Teams
         .Where(t => t.name == nameOfTeam)
         .FirstOrDefault()
         .description = newDescription;
         context.SaveChanges();
     }
 }
Exemple #12
0
 public void ModifyUserPassword(string mailOfUser, string newPassword)
 {
     using (ContextDB context = new ContextDB())
     {
         context.Users
         .Where(a => a.mail == mailOfUser)
         .FirstOrDefault()
         .password = newPassword;
         context.SaveChanges();
     }
 }
Exemple #13
0
 public List <Team> GetTeams(User user)
 {
     using (ContextDB context = new ContextDB())
     {
         context.Configuration.ProxyCreationEnabled = false;
         var query = context.Users
                     .Where(u => u.mail == user.mail)
                     .Include(u => u.teams)
                     .FirstOrDefault();
         List <Team> teams = new List <Team>();
         teams = query.teams.ToList();
         return(teams);
     }
 }
        public Blackboard GetBlackboard(string name, Team team)
        {
            Blackboard blackboard = new Blackboard();

            using (ContextDB context = new ContextDB())
            {
                blackboard = context.Blackboards
                             .Where(b => b.name == name)
                             .FirstOrDefault();
            }
            if (BlackboardNotDefined(blackboard))
            {
                throw new BlackboardException(ExceptionMessage.blackboardNotExist);
            }
            return(blackboard);
        }
Exemple #15
0
        public bool ExistsUser(User user)
        {
            bool exists = true;

            using (ContextDB context = new ContextDB())
            {
                user = context.Users
                       .Where(a => a.mail == user.mail)
                       .FirstOrDefault();
            }
            if (UserNotDefined(user))
            {
                exists = false;
            }
            return(exists);
        }
        public bool ExistsBlackboard(Blackboard blackboard)
        {
            bool exists = true;

            using (ContextDB context = new ContextDB())
            {
                blackboard = context.Blackboards
                             .Where(b => b.name == blackboard.name)
                             .FirstOrDefault();;
            }
            if (BlackboardNotDefined(blackboard))
            {
                exists = false;
            }
            return(exists);
        }
Exemple #17
0
        public bool ExistsTeam(Team team)
        {
            bool exist = true;

            using (ContextDB context = new ContextDB())
            {
                team = context.Teams
                       .Where(t => t.name == team.name)
                       .FirstOrDefault();
            }
            if (TeamNotDefined(team))
            {
                exist = false;
            }
            return(exist);
        }
Exemple #18
0
        public User GetUser(string mailOfUser)
        {
            User user = null;

            using (ContextDB context = new ContextDB())
            {
                context.Configuration.ProxyCreationEnabled = false;
                user = context.Users
                       .Where(u => u.mail == mailOfUser)
                       .Include(u => u.teams)
                       .FirstOrDefault();
            }
            if (UserNotDefined(user))
            {
                throw new UserException(ExceptionMessage.userNotExist);
            }
            return(user);
        }
Exemple #19
0
        public Team GetTeam(string nameOfTeam)
        {
            Team team = new Team();

            using (ContextDB context = new ContextDB())
            {
                context.Configuration.ProxyCreationEnabled = false;
                team = context.Teams
                       .Where(t => t.name == nameOfTeam)
                       .Include(t => t.usersInTeam)
                       .FirstOrDefault();
            }
            if (TeamNotDefined(team))
            {
                throw new TeamException(ExceptionMessage.teamNotExists);
            }
            return(team);
        }
Exemple #20
0
 public void ModifyTeamUsers(Team team, ICollection <User> users)
 {
     using (ContextDB context = new ContextDB())
     {
         List <User> newUsersInTeam = new List <User>();
         var         teamToModify   = context.Teams.Find(team.OIDTeam);
         foreach (User user in users)
         {
             var userToAdd = context.Users.Find(user.OIDUser);
             newUsersInTeam.Add(userToAdd);
         }
         context.Teams
         .Where(t => t.name == team.name)
         .Include(t => t.usersInTeam)
         .FirstOrDefault()
         .usersInTeam = newUsersInTeam;
         context.SaveChanges();
     }
 }
Exemple #21
0
        public void DeleteUser(string mailOfUser)
        {
            User user = null;

            using (ContextDB context = new ContextDB())
            {
                context.Configuration.ProxyCreationEnabled = false;
                context.Users.Include(a => a.teams).Load();
                user = context.Users
                       .Where(a => a.mail == mailOfUser)
                       .Include(a => a.teams)
                       .FirstOrDefault();
                context.Users
                .Where(a => a.mail == mailOfUser)
                .FirstOrDefault()
                .active = false;
                context.SaveChanges();
            }
            foreach (Team team in user.teams)
            {
                TeamFunctions.RemoveUser(team, user);
            }
        }
Exemple #22
0
 public void AddTeam(Team team)
 {
     using (ContextDB context = new ContextDB())
     {
         team.creator = (Administrator)context.Users.Find(team.creator.OIDUser);
         List <User> newUsers = new List <User>();
         for (int i = 0; i < team.usersInTeam.Count; i++)
         {
             var user = team.usersInTeam.ToList()[i];
             if (!user.mail.Equals(team.creator.mail))
             {
                 newUsers.Add(context.Users.Find(user.OIDUser));
             }
             else
             {
                 newUsers.Add(team.creator);
             }
         }
         team.usersInTeam = newUsers;
         context.Teams.Add(team);
         context.SaveChanges();
     }
 }