public void DeleteFolder(object folderId) { var folder = ProviderInfo.GetFolderById(folderId); using (var dbManager = new DbManager(FileConstant.DatabaseId)) { using (var tx = dbManager.BeginTransaction()) { var hashIDs = dbManager.ExecuteList( Query("files_thirdparty_id_mapping") .Select("hash_id") .Where(Exp.Like("id", folder.ServerRelativeUrl, SqlLike.StartWith))) .ConvertAll(x => x[0]); dbManager.ExecuteNonQuery(Delete("files_tag_link").Where(Exp.In("entry_id", hashIDs))); dbManager.ExecuteNonQuery( Delete("files_tag") .Where(Exp.EqColumns("0", Query("files_tag_link l").SelectCount().Where(Exp.EqColumns("tag_id", "id"))))); dbManager.ExecuteNonQuery(Delete("files_security").Where(Exp.In("entry_id", hashIDs))); dbManager.ExecuteNonQuery(Delete("files_thirdparty_id_mapping").Where(Exp.In("hash_id", hashIDs))); tx.Commit(); } } ProviderInfo.DeleteFolder((string)folderId); }
public void DeleteFolder(string folderId) { var folder = ProviderInfo.GetFolderById(folderId); using (var tx = FilesDbContext.Database.BeginTransaction()) { var hashIDs = Query(FilesDbContext.ThirdpartyIdMapping) .Where(r => r.Id.StartsWith(folder.ServerRelativeUrl)) .Select(r => r.HashId) .ToList(); var link = Query(FilesDbContext.TagLink) .Where(r => hashIDs.Any(h => h == r.EntryId)) .ToList(); FilesDbContext.TagLink.RemoveRange(link); FilesDbContext.SaveChanges(); var tagsToRemove = from ft in FilesDbContext.Tag join ftl in FilesDbContext.TagLink.DefaultIfEmpty() on new { TenantId = ft.TenantId, Id = ft.Id } equals new { TenantId = ftl.TenantId, Id = ftl.TagId } where ftl == null select ft; FilesDbContext.Tag.RemoveRange(tagsToRemove.ToList()); var securityToDelete = Query(FilesDbContext.Security) .Where(r => hashIDs.Any(h => h == r.EntryId)); FilesDbContext.Security.RemoveRange(securityToDelete); FilesDbContext.SaveChanges(); var mappingToDelete = Query(FilesDbContext.ThirdpartyIdMapping) .Where(r => hashIDs.Any(h => h == r.HashId)); FilesDbContext.ThirdpartyIdMapping.RemoveRange(mappingToDelete); FilesDbContext.SaveChanges(); tx.Commit(); } ProviderInfo.DeleteFolder(folderId); }
public void DeleteFolder(string folderId) { var folder = ProviderInfo.GetFolderById(folderId); using (var tx = FilesDbContext.Database.BeginTransaction()) { var hashIDs = Query(FilesDbContext.ThirdpartyIdMapping) .Where(r => r.Id.StartsWith(folder.ServerRelativeUrl)) .Select(r => r.HashId) .ToList(); var link = Query(FilesDbContext.TagLink) .Where(r => hashIDs.Any(h => h == r.EntryId)) .ToList(); FilesDbContext.TagLink.RemoveRange(link); FilesDbContext.SaveChanges(); var tagsToRemove = Query(FilesDbContext.Tag) .Where(r => !Query(FilesDbContext.TagLink).Where(a => a.TagId == r.Id).Any()); FilesDbContext.Tag.RemoveRange(tagsToRemove); var securityToDelete = Query(FilesDbContext.Security) .Where(r => hashIDs.Any(h => h == r.EntryId)); FilesDbContext.Security.RemoveRange(securityToDelete); FilesDbContext.SaveChanges(); var mappingToDelete = Query(FilesDbContext.ThirdpartyIdMapping) .Where(r => hashIDs.Any(h => h == r.HashId)); FilesDbContext.ThirdpartyIdMapping.RemoveRange(mappingToDelete); FilesDbContext.SaveChanges(); tx.Commit(); } ProviderInfo.DeleteFolder(folderId); }