private void RemoveFromCurrentFolder(IStorageFile entity) { List <StorageFolder> folders = _storageFolderRepository.Get().Where(c => c.Files.Any(t => t.Id == entity.Id)).ToList(); int lastIndex = entity.Path.LastIndexOf('/'); var path = entity.Path; if (lastIndex != -1) { path = entity.Path.Substring(0, lastIndex); } //remove from folder if new path differs if (folders.Any() && folders[0].Path != path) { StorageFolder currentFolder = folders[0]; List <IStorageFile> childFiles = currentFolder.Files; int index = -1; foreach (IStorageFile file in childFiles) { if (file.Id == entity.Id) { index = childFiles.FindIndex(c => c.Id == file.Id); } } if (index != -1) { childFiles.RemoveAt(index); } currentFolder.Files = childFiles; _storageFolderRepository.Update(currentFolder); } }
public IStorageFile Update(IStorageFile entity) { //remove from current folder RemoveFromCurrentFolder(entity); entity = _repository.Update((StorageFile)entity); //recurse folders int lastIndex = entity.Path.LastIndexOf('/'); if (lastIndex != -1) { var path = entity.Path.Substring(0, lastIndex); RecurseForCreateFolderPath(path, entity.Id, entity); } return(entity); }
public IStorageFolder Update(IStorageFolder entity) { var currentFolder = _repository.Find(c => c.Id == entity.Id).SingleOrDefault(); if (currentFolder != null && currentFolder.Path != entity.Path) { List <IStorageFile> files = entity.Files; foreach (IStorageFile file in files) { var filePath = ""; var oPath = ""; var obj = _fileRepository.Find(c => c.Id == file.Id).SingleOrDefault(); filePath = obj.Path; oPath = obj.Path; int index = filePath.LastIndexOf('/'); string fileName = filePath; if (index != -1) { fileName = filePath.Substring(index + 1); } oPath = entity.Path + "/" + fileName; var f = (StorageFile)file; f.Path = oPath; _fileRepository.Update(f); } List <IStorageFolder> folders = entity.Folders; foreach (IStorageFolder folder in folders) { var filePath = ""; var oPath = ""; var obj = Get(folder.Id); filePath = obj.Path; oPath = obj.Path; int index = filePath.LastIndexOf('/'); string fileName = filePath; if (index != -1) { fileName = filePath.Substring(index + 1); } oPath = entity.Path + "/" + fileName; var f = (StorageFolder)folder; f.Path = oPath; _repository.Update(f); } } entity = _repository.Update((StorageFolder)entity); return(entity); }