예제 #1
0
        public async Task <bool> ReplaceFolderOfEntryAsync(FolderModel folder, FolderModel oldFolder, FolderModel newFolder)
        {
            bool savePls = false;

            if (!newFolder.Folders.Contains(folder))
            {
                newFolder.Folders.AddUniqueSorted(folder);
            }
            if (!folder.ParentIds.Contains(newFolder.GetId()))
            {
                folder.ParentIds.Add(newFolder.GetId());
                savePls = true;
            }
            if (oldFolder.Folders.Contains(folder))
            {
                oldFolder.Folders.Remove(folder);
            }
            if (folder.ParentIds.Contains(oldFolder.GetId()))
            {
                folder.ParentIds.Remove(oldFolder.GetId());
                savePls = true;
            }
            if (savePls)
            {
                return(await _folderRepository.SaveAsync(folder));
            }
            return(true);
        }
예제 #2
0
        public async Task <bool> ReplaceFolderOfEntryAsync(EntryModel entryModel, FolderModel oldFolder, FolderModel newFolder)
        {
            bool savePls = false;

            if (!newFolder.Entries.Contains(entryModel))
            {
                newFolder.Entries.AddUniqueSorted(entryModel);
            }
            if (!entryModel.ParentIds.Contains(newFolder.GetId()))
            {
                entryModel.ParentIds.Add(newFolder.GetId());
                savePls = true;
            }
            if (oldFolder.Entries.Contains(entryModel))
            {
                oldFolder.Entries.Remove(entryModel);
            }
            if (entryModel.ParentIds.Contains(oldFolder.GetId()))
            {
                entryModel.ParentIds.Remove(oldFolder.GetId());
                savePls = true;
            }
            if (savePls)
            {
                return(await _entryRepository.SaveAsync(entryModel));
            }
            return(true);
        }
예제 #3
0
 public async Task <bool> AddEntryToFolderAsync(EntryModel entryModel, FolderModel folder)
 {
     if (!folder.Entries.Contains(entryModel))
     {
         folder.Entries.AddUniqueSorted(entryModel);
     }
     if (!entryModel.ParentIds.Contains(folder.GetId()))
     {
         entryModel.ParentIds.Add(folder.GetId());
         return(await _entryRepository.SaveAsync(entryModel));
     }
     return(true);
 }
예제 #4
0
 public async Task <bool> RemoveEntryFromFolderAsync(EntryModel entryModel, FolderModel folder)
 {
     if (folder.Entries.Contains(entryModel))
     {
         folder.Entries.Remove(entryModel);
     }
     if (entryModel.ParentIds.Contains(folder.GetId()))
     {
         entryModel.ParentIds.Remove(folder.GetId());
         return(await _entryRepository.SaveAsync(entryModel));
     }
     return(true);
 }
예제 #5
0
        public FolderModel CreateFolder(FolderModel parentFolderModel)
        {
            var entry = new FolderModel();

            entry.ParentIds.Add(parentFolderModel.GetId());
            return(entry);
        }
예제 #6
0
        public EntryModel CreateEntry(FolderModel parentFolderModel, ContentType type)
        {
            var entry = new EntryModel {
                ContentType = type
            };

            entry.ParentIds.Add(parentFolderModel.GetId());
            return(entry);
        }
예제 #7
0
 public async Task <bool> RemoveFolderAsync(FolderModel folderModel)
 {
     //removing parent ids
     foreach (var entryModel in _entries)
     {
         if (entryModel.ParentIds.Contains(folderModel.GetId()))
         {
             entryModel.ParentIds.Remove(folderModel.GetId());
             await _entryRepository.SaveAsync(entryModel);
         }
     }
     foreach (var folder in _folders)
     {
         if (folder.ParentIds.Contains(folderModel.GetId()))
         {
             folder.ParentIds.Remove(folderModel.GetId());
             await _folderRepository.SaveAsync(folder);
         }
     }
     return(await _folderRepository.RemoveAsync(folderModel));
 }
예제 #8
0
 private FolderModel TryFindFolderModel(FolderModel model, Guid guid)
 {
     if (model.GetId() == guid)
     {
         return(model);
     }
     foreach (var modelFolder in model.Folders)
     {
         var folder = TryFindFolderModel(modelFolder, guid);
         if (folder != null)
         {
             return(folder);
         }
     }
     return(null);
 }
예제 #9
0
        private void AddFolder(FolderModel folder)
        {
            if (!FixParentModel(folder))
            {
                return;
            }

            //already added
            if (_folderDic.ContainsKey(folder.GetId()))
            {
                return;
            }

            //else add to tree structure

            List <FolderModel> children;
            List <EntryModel>  entries;
            var parentsToAdd = new List <FolderModel>();

            lock (this)
            {
                //already added
                if (_folderDic.ContainsKey(folder.GetId()))
                {
                    return;
                }

                //do parent stuff
                _folderGuidToFolderDic.TryRemove(folder.GetId(), out children);
                _folderGuidToEntryDic.TryRemove(folder.GetId(), out entries);
                _folderDic[folder.GetId()] = folder;

                //if only garbage guid we are finished here
                if (folder.ParentIds.Contains(_garbageGuid))
                {
                    _folderDic[_garbageGuid].Folders.AddUniqueSorted(folder);
                }
                else
                {
                    //do children stuff
                    foreach (var folderParentId in folder.ParentIds)
                    {
                        if (!_folderDic.ContainsKey(folderParentId))
                        {
                            //parent folder not initialized yet
                            if (!_folderGuidToFolderDic.ContainsKey(folderParentId))
                            {
                                _folderGuidToFolderDic[folderParentId] = new List <FolderModel>();
                            }

                            _folderGuidToFolderDic[folderParentId].Add(folder);
                        }
                        else
                        {
                            //parent folder active
                            parentsToAdd.Add(_folderDic[folderParentId]);
                        }
                    }
                }
            }

            //add children
            if (children != null)
            {
                foreach (var folderModel in children)
                {
                    folder.Folders.AddUniqueSorted(folderModel);
                }
            }

            //add entries
            if (entries != null)
            {
                foreach (var entry in entries)
                {
                    folder.Entries.AddUniqueSorted(entry);
                }
            }

            //add itself to all parents
            foreach (var folderModel in parentsToAdd)
            {
                folderModel.Folders.AddUniqueSorted(folder);
            }

            AddToSearchIndex(folder);
        }