/// <summary> /// Add a user to a section /// switchuser indicates that the user should be dropped /// from all other sections /// Email owner of the group if actor != username /// </summary> public bool AddUser(int sectionID, string username, bool switchuser) { Section section = GetInfo(sectionID); //Check permission Authorize(section.CourseID, Permission.SECTION, "update", sectionID, null); //Check to see if the user is in this group already string actor = Identity.Name; User.UserList users = GetMembers(sectionID); User user = new User(); user.UserName = username; if (users.Contains(user)) { throw new DataAccessException("User already exists in the section"); } //Send email to the owner if the owner did not make the change if (actor != section.Owner) { new EmailWizard(m_ident).SendByUsername(section.Owner, "FrontDesk Section Notification", String.Format(Globals.GetMessage("SectionAdd"), actor, username, System.DateTime.Now)); } //TODO: Enforce policy of section membership //Create the membership m_dp.CreateSectionMember(sectionID, username, switchuser); return(true); }
/// <summary> /// Add users to the course from an XML stream /// </summary> public void BatchAddUsers(Stream xmlStream, int courseID, bool sync) { //TODO: Error checking User mem = new User(); Users usersDB = new Users(m_ident); DataSet xmldata = new DataSet(); xmldata.ReadXml(xmlStream); DataRowCollection users = xmldata.Tables["User"].Rows; IProviderTransaction tran = m_dp.BeginTransaction(); foreach (DataRow row in users) { mem.UserName = (string)row["UserName"]; string role = (string)row["Role"]; //Make sure the user is in the system if (null == usersDB.GetInfo(mem.UserName, tran)) { m_dp.RollbackTransaction(tran); throw new DataAccessException("User: "******" is not in the FrontDesk database"); } User.UserList cmems = GetMembers(courseID, tran); //The user already exists in the course if (cmems.Contains(mem)) { if (sync) { UpdateRole(mem.UserName, courseID, role, tran); } else { m_dp.RollbackTransaction(tran); throw new DataAccessException("User: "******" already exists in the course. " + "Do a merge if you want to change the roles"); } } else { m_dp.CreateCourseMember(mem.UserName, courseID, role, tran); } } m_dp.CommitTransaction(tran); }