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); } }
public void AddAdministrator(Administrator administrator) { using (ContextDB context = new ContextDB()) { context.Administrators.Add(administrator); context.SaveChanges(); } }
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(); } }
public void AddComment(Comment comment) { using (ContextDB context = new ContextDB()) { context.Comments.Add(comment); context.SaveChanges(); } }
public void DeleteTeam(Team team) { using (ContextDB context = new ContextDB()) { var query = context.Teams.Find(team.OIDTeam); context.Teams.Remove(query); context.SaveChanges(); } }
public void ModifyTeamMaxUsers(string nameOfTeam, int newMaxUsers) { using (ContextDB context = new ContextDB()) { context.Teams .Where(t => t.name == nameOfTeam) .FirstOrDefault().maxUsers = newMaxUsers; context.SaveChanges(); } }
public List <Team> LoadTeams() { List <Team> allTeams = new List <Team>(); using (ContextDB context = new ContextDB()) { allTeams = context.Teams.ToList(); } return(allTeams); }
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); }
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); } }
public void ModifyTeamDescription(string nameOfTeam, string newDescription) { using (ContextDB context = new ContextDB()) { context.Teams .Where(t => t.name == nameOfTeam) .FirstOrDefault() .description = newDescription; context.SaveChanges(); } }
public void ModifyUserPassword(string mailOfUser, string newPassword) { using (ContextDB context = new ContextDB()) { context.Users .Where(a => a.mail == mailOfUser) .FirstOrDefault() .password = newPassword; context.SaveChanges(); } }
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); }
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); }
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); }
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); }
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); }
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(); } }
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); } }
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(); } }