private IFolder CreateFolder(string path, int?folderId = null, IDictionary <string, string> meta = null) { if (string.IsNullOrEmpty(path)) { return(null); } var parts = path.Split(new char[] { '/', '\\' }).Where(f => !string.IsNullOrEmpty(f)).ToList(); if (!parts.Any()) { return(null); } using (var db = GetUpdateContext()) { var folderName = parts.FirstOrDefault(); var subFolder = db.Folders .Where(f => !f.Deleted && (f.ParentId == folderId || f.ParentId == null && folderId == null) && f.Name == folderName) .FirstOrDefault(); if (subFolder == null) { subFolder = new ef_DBFolder() { Name = folderName, Created = DateTime.Now, ParentId = folderId }; db.Folders.Add(subFolder); db.SaveChanges(); } if (parts.Count() == 1) { var newFolder = subFolder.ToEFFolder(); CreateFolderEventHandler handler = CreateFolderEvent; if (handler != null) { handler(this, new CreateFolderEventArgs() { Folder = newFolder, Meta = meta }); } return(newFolder); } else { parts.RemoveAt(0); return(CreateFolder(string.Join("/", parts.ToArray()), subFolder.Id)); } } }
private string GetFolderFullPath(ef_DBFolder folder) { var parentFolder = folder.Parent; if (parentFolder != null) { var parentPath = GetFolderFullPath(parentFolder); return(parentPath += "/" + folder.Name); } return(folder.Name); }
private string GetFolderFullPath(ef_DBFolder folder) { var parentFolder = folder.Parent; if (parentFolder != null) { var parentPath = GetFolderFullPath(parentFolder); return(Path.Combine(parentPath, folder.Name)); } return(folder.Name); }