示例#1
0
        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);
            }
        }
示例#2
0
 public IStorageFile Get(int id)
 {
     return(_repository.Find(c => c.Id == id).SingleOrDefault());
 }
        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);
        }