/// <summary> /// Adds a inputed user to the inputed project and set his role in the project /// JDP /// </summary> /// <param name="projectID"></param> /// <param name="userName"></param> /// <param name="owner"></param> public void addUserToProject(int projectID, string userName, bool owner) { //checkes if the user is part of the database if (!isRegisteredUser(userName)) { return; } //checks if the user is already part of the project if (isAlreadyConnectedToProject(projectID, userName)) { return; } ProjectUserConnectors newUserProjectConnection = new ProjectUserConnectors(); newUserProjectConnection.projectId = projectID; newUserProjectConnection.userName = userName; //sets the role of newly added user depending on the value of the owner variable if (owner == true) { newUserProjectConnection.role = "owner"; } else { newUserProjectConnection.role = "guest"; } newUserProjectConnection.userId = null; _db.projectUserConnectors.Add(newUserProjectConnection); _db.SaveChanges(); }
/// <summary> /// checks if the user that is sent in is already part of a /// project that is in the project that is sent in /// JHU /// </summary> /// <param name="projectID"></param> /// <param name="userName"></param> /// <returns></returns> private bool isAlreadyConnectedToProject(int projectID, string userName) { ProjectUserConnectors connection = _db.projectUserConnectors.FirstOrDefault(x => (x.projectId == projectID && x.userName == userName)); if (connection == null) { return(false); } else { return(true); } }