public IStorageFolder Add(IStorageFolder entity) { var storageFolder = new StorageFolder(); storageFolder.Path = entity.Path; storageFolder.Files = entity.Files; storageFolder = _repository.Add(storageFolder); //recurse folders int lastIndex = storageFolder.Path.LastIndexOf('/'); if (lastIndex != -1) { var path = storageFolder.Path.Substring(0, lastIndex); //if (string.IsNullOrEmpty(storageFolder.Path)) // storageFolder.Path = "/"; RecurseForCreateFolderPath(path, storageFolder.Id, storageFolder); } return(storageFolder); }
public IStorageFile Add(IStorageFile entity) { var storageFile = new StorageFile(); storageFile.Path = entity.Path; storageFile = _repository.Add(storageFile); int lastIndex = storageFile.Path.LastIndexOf('/'); if (lastIndex != -1) { int id = storageFile.Id; var path = storageFile.Path.Substring(0, lastIndex); RecurseForCreateFolderPath(path, id, storageFile); } return(storageFile); }
private void RecurseForCreateFolderPath(string path, int childId, IStorageEntity obj) { //check for root folder if (string.IsNullOrEmpty(path)) { path = "/"; } IList <StorageFolder> array = _storageFolderRepository.Find(c => c.Path == path).ToList(); if (!array.Any()) { //folder does not exist so insert and move up StorageFolder folder = new StorageFolder(); folder.Path = path; if (obj != null) { if (obj.GetType() == typeof(StorageFile)) { folder.Files.Add((StorageFile)obj); } if (obj.GetType() == typeof(StorageFolder)) { folder.Folders.Add((StorageFolder)obj); } } folder = _storageFolderRepository.Add(folder); if (!string.IsNullOrEmpty(path.Trim())) { int lastIndex = path.LastIndexOf('/'); if (lastIndex != -1) { path = path.Substring(0, lastIndex); RecurseForCreateFolderPath(path, folder.Id, folder); } } } else { StorageFolder j_obj = array[0]; List <IStorageFile> files = j_obj.Files; var id = j_obj.Id; if (id != childId) { var list = new List <StorageFile>(); foreach (StorageFile file in files) { list.Add(file); } if (!list.Where(c => c.Id == childId).Any()) { files.Add((StorageFile)obj); } } j_obj.Files = files; _storageFolderRepository.Update(j_obj); } }