public bool Create(string Folder, string Parent)
 {
     if (Folder != null && !Folder.Equals(string.Empty))
     {
         if (!folderRepo.GetFolderNamesOnlyByPathParent(Parent).Contains(Folder))
         {
             Folder newFolder = new Folder
             {
                 BookmarkType = BookmarkEntity.Type.FOLDER,
                 Name         = Folder,
                 ReadOnly     = false
             };
             if (Parent != null && !Parent.Equals(string.Empty))
             {
                 newFolder.ParentPath = Parent;
             }
             else
             {
                 newFolder.ParentPath = "Root";
             }
             folderRepo.InsertAsync(newFolder);
             db.SaveChangesAsync();
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 2
0
        public async Task <IActionResult> Lock(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var bookmarkEntity = await _context.BookmarkEntity.SingleOrDefaultAsync(m => m.Id == id);

            if (bookmarkEntity == null)
            {
                return(NotFound());
            }

            Tuple <string, string> tuple = GetFolderAndParentFolder((bookmarkEntity.ParentPath == "Root" || bookmarkEntity.ParentPath == "")
                ? bookmarkEntity.Name : bookmarkEntity.ParentPath);
            var parent = bookmarkEntityRepo.GetBookMarkByNameAndParentPath(tuple.Item1, tuple.Item2);

            if (parent == null)
            {
                return(NotFound());
            }

            if (!bookmarkEntity.Equals(parent))
            {
                if ((bookmarkEntity.ParentPath != "Root" || bookmarkEntity.ParentPath != "") && parent.ReadOnly)
                {
                    return(View("Error", new ErrorViewModel()));
                }
            }

            bookmarkEntity.ReadOnly = true;
            _context.Update(bookmarkEntity);

            LockChildren((bookmarkEntity.ParentPath == "Root" || bookmarkEntity.ParentPath == "")
                ? bookmarkEntity.Name : bookmarkEntity.ParentPath + "|" + bookmarkEntity.Name);


            await _context.SaveChangesAsync();

            return(Redirect("/BookmarkEntities/ViewContent/" + parent.Id));
        }