public void RollbackOnError(UserProcessState state, string userName) { switch (state) { case UserProcessState.WIN_USER_ERROR: //Hvis brugeroprettelse er færdig, stop her (der kan være nogel oprettede brugere i batch oprettelse) break; case UserProcessState.WIN_GROUP_ERROR: { UserPrincipal user = UserPrincipal.FindByIdentity(context, userName); UserManagement management = new UserManagement(user); management.RemoveWindowsAccount(user); //textBox2.Text += Enum.GetName(typeof(UserProcessState), BatchState.State) + "\n"; break; } case UserProcessState.IIS_WEBSITE_ERROR: { break; } case UserProcessState.VIRTUAL_DIRECTORY_ERROR: { //Hvis virtual directory oprettelse fejler, slet bruger og website UserPrincipal user = UserPrincipal.FindByIdentity(context, userName); UserManagement management = new UserManagement(user); string physicalPath = "C:\\inetpub\\wwwroot\\" + userName + "\\"; iis.RemoveWebsite(userName, physicalPath); } break; case UserProcessState.SQL_LOGIN_ERROR: { //hvis sql login fejler, slet vdir, website,bruger Student student = db.Students.Where(x => x.Credentials.FTPUserName == userName).Single(); UserPrincipal user = UserPrincipal.FindByIdentity(context, student.Credentials.FTPUserName); UserManagement management = new UserManagement(user); string physicalPath = "C:\\inetpub\\wwwroot\\" + student.Credentials.FTPUserName + "\\"; iis.RemoveWebsite(student.Credentials.FTPUserName, physicalPath); iis.RemoveVirtualDirectory("_FTP", "/" + student.Credentials.FTPUserName, physicalPath); } break; case UserProcessState.SQL_DB_ERROR: { //hvis dboprettelse fejler, slet dblogin,vdir,website og bruger Student student = db.Students.Where(x => x.Credentials.FTPUserName == userName).Single(); UserPrincipal user = UserPrincipal.FindByIdentity(context, student.Credentials.FTPUserName); UserManagement management = new UserManagement(user); string physicalPath = "C:\\inetpub\\wwwroot\\" + student.Credentials.FTPUserName + "\\"; iis.RemoveWebsite(student.Credentials.FTPUserName, physicalPath); iis.RemoveVirtualDirectory("_FTP", "/" + student.Credentials.FTPUserName, physicalPath); } break; case UserProcessState.SQL_USER_ERROR: { //hvis dboprettelse fejler, slet alt for denne bruger Student student = db.Students.Where(x => x.Credentials.FTPUserName == userName).Single(); UserPrincipal user = UserPrincipal.FindByIdentity(context, student.Credentials.FTPUserName); UserManagement management = new UserManagement(user); string physicalPath = "C:\\inetpub\\wwwroot\\" + student.Credentials.FTPUserName + "\\"; iis.RemoveWebsite(student.Credentials.FTPUserName, physicalPath); iis.RemoveVirtualDirectory("_FTP", "/" + student.Credentials.FTPUserName, physicalPath); sql.DeleteLoginAndDB(student.Credentials.FTPUserName, student.Credentials.FTPUserName); break; } case UserProcessState.SQL_INSERT_USER_DATA_ERROR: { //hvis dboprettelse fejler, slet alt for denne bruger //UserPrincipal user = UserPrincipal.FindByIdentity(context, student.Credentials.FTPUserName); //UserManagement management = new UserManagement(user); //string physicalPath = "C:\\inetpub\\wwwroot\\" + student.Credentials.FTPUserName + "\\"; //iis.RemoveWebsite(student.Credentials.FTPUserName, physicalPath); //iis.RemoveVirtualDirectory("_FTP", "/" + student.Credentials.FTPUserName, physicalPath); //sql.DeleteLoginAndDB(student.Credentials.FTPUserName, student.Credentials.FTPUserName); break; } } }
public Student DeleteUserWebsiteFTPDatabase(int studentId) { try { Student student = db.Students.Find(studentId); UserPrincipal user = UserPrincipal.FindByIdentity(context, student.Credentials.FTPUserName); UserManagement mngtmnt = new UserManagement(user); mngtmnt.RemoveWindowsAccount(user); string physicalPath = "C:\\inetpub\\wwwroot\\" + student.Credentials.FTPUserName + "\\"; iis.RemoveWebsite(student.Credentials.FTPUserName, physicalPath); iis.RemoveVirtualDirectory("_FTP", "/" + student.Credentials.FTPUserName, physicalPath); sql.DeleteLoginAndDB(student.Credentials.FTPUserName, student.Credentials.FTPUserName); db.Students.Remove(student); db.Credentials.Remove(db.Credentials.Find(student.CredentialsId)); return student; } catch (Exception) { throw; } }