Exemplo n.º 1
0
        private IActionResult toEdit(BookmarkEntity bookmarkEntity)
        {
            if (bookmarkEntity.ReadOnly)
            {
                return(View("Error", new ErrorViewModel("Item Readonly!", "\'" + bookmarkEntity.Name + "\' is readonly, therefor it cannot be edit.")));
            }
            switch (bookmarkEntity.BookmarkType)
            {
            case BookmarkEntity.Type.FOLDER:
            {
                return(View("Folder/Edit", bookmarkEntity));
            }

            case BookmarkEntity.Type.LINK:
            {
                return(View("Link/Edit", bookmarkEntity));
            }

            case BookmarkEntity.Type.LOCATION:
            {
                return(View("Location/Edit", bookmarkEntity));
            }

            case BookmarkEntity.Type.TEXTFILE:
            {
                return(View("Textfile/Edit", bookmarkEntity));
            }

            default:
            {
                return(View("Edit"));
            }
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id, Title, Content, BookmarkType,Name,ReadOnly,ParentPath")] BookmarkEntity bookmarkEntity)
        {
            if (id != bookmarkEntity.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(bookmarkEntity);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BookmarkEntityExists(bookmarkEntity.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(bookmarkEntity));
        }
Exemplo n.º 3
0
        private dynamic GenerateSubTree(BookmarkEntity temp)
        {
            var tree = new BookMarkTreeHelperModel
            {
                folder     = temp.Name,
                ParentPath = temp.ParentPath,
                type       = temp.BookmarkType
            };
            List <BookmarkEntity> bookMark = null;

            if (temp.ParentPath != null &&
                (temp.ParentPath != "" && temp.ParentPath != "Root"))
            {
                bookMark = bookmarkEntityRepo.GetListOfSubBookMarks(temp.ParentPath + "|" + temp.Name);
            }
            else
            {
                bookMark = bookmarkEntityRepo.GetListOfSubBookMarks(temp.Name);
            }

            if (bookMark != null &&
                bookMark.Count > 0)
            {
                tree.subBookmarks = new List <BookMarkTreeHelperModel>();
                foreach (BookmarkEntity subBookMark in bookMark)
                {
                    tree.subBookmarks.Add(GenerateSubTree(subBookMark));
                }
            }
            return(tree);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Adds the thread to bookmarks.
        /// </summary>
        /// <param name="userID">User ID.</param>
        /// <param name="threadID">Thread ID.</param>
        /// <returns>true if save succeeded, false otherwise</returns>
        public static bool AddThreadToBookmarks(int userID, int threadID)
        {
            BookmarkEntity newBookmark = new BookmarkEntity();

            newBookmark.UserID   = userID;
            newBookmark.ThreadID = threadID;
            return(newBookmark.Save());
        }
Exemplo n.º 5
0
 public BookmarkModel ToModel(BookmarkEntity entity)
 {
     return(new BookmarkModel()
     {
         UserId = entity.UserId,
         PostId = entity.PostId
     });
 }
Exemplo n.º 6
0
        /// <summary>Creates a new, empty BookmarkEntity object.</summary>
        /// <returns>A new, empty BookmarkEntity object.</returns>
        public override IEntity Create()
        {
            IEntity toReturn = new BookmarkEntity();

            // __LLBLGENPRO_USER_CODE_REGION_START CreateNewBookmark
            // __LLBLGENPRO_USER_CODE_REGION_END
            return(toReturn);
        }
Exemplo n.º 7
0
        async Task FetchFavicon(BookmarkEntity bookmark, string url)
        {
            try
            {
                if (_fetcher == null || _servicesFactory == null)
                {
                    return;
                }

                var scope      = _servicesFactory.CreateScope();
                var repository = scope.ServiceProvider.GetService(typeof(IBookmarkRepository)) as IBookmarkRepository;
                if (repository == null)
                {
                    _logger.LogWarning("Unable to get a repository from ServicesScopeFactory!");
                    return;
                }

                var result = await _fetcher.GetFaviconFromUrl(url);

                var filename = result.filename;
                var payload  = result.payload;
                // combine icon with bookmark id
                filename = bookmark.Id + "_" + filename;
                if (payload != null && payload.Length > 0)
                {
                    _logger.LogDebug($"got a favicon payload of length '{payload.Length}' for url '{url}'");

                    var rootPath    = _webHostEnv.ContentRootPath;
                    var iconPath    = _faviconSettings.StoragePath;
                    var storagePath = Path.Combine(rootPath, iconPath);
                    var path        = Path.Combine(storagePath, filename);
                    await System.IO.File.WriteAllBytesAsync(path, payload);

                    if (System.IO.File.Exists(path))
                    {
                        // also update the favicon
                        await repository !.InUnitOfWorkAsync <bool>(async() => {
                            var bm      = bookmark;
                            bm.Favicon  = filename;
                            var updated = await repository.Update(bm);
                            return(updated != null ? (true, true) : (false, false));
                        });
                    }
                }
                else
                {
                    _logger.LogDebug($"No favicon payload for url '{url}'.");
                }
            }
            catch (Exception EX)
            {
                _logger.LogError($"Error during favicon fetch/update: {EX.Message}; stack: {EX.StackTrace}");
            }
        }
Exemplo n.º 8
0
 // GET: BookmarkEntities/CreateType
 public IActionResult CreateType(string ParentPath, string returnUrl)
 {
     if (ParentPath == null || ParentPath.Equals(""))
     {
         ViewBag.Path = GetAllPossiblePath();
     }
     else
     {
         ViewBag.Path = GetCurrentPath(ParentPath);
     }
     ViewBag.Types     = BookmarkEntity.Gettypes();
     ViewBag.returnUrl = returnUrl;
     return(View("Create"));
 }
Exemplo n.º 9
0
 BookmarkModel ToModel(BookmarkEntity entity)
 {
     return(new BookmarkModel {
         ChildCount = entity.ChildCount,
         Created = entity.Created,
         DisplayName = entity.DisplayName,
         Id = entity.Id,
         Modified = entity.Modified,
         Path = entity.Path,
         SortOrder = entity.SortOrder,
         Type = entity.Type == Store.ItemType.Folder ? ItemType.Folder : ItemType.Node,
         Url = entity.Url,
         Favicon = entity.Favicon,
         AccessCount = entity.AccessCount
     });
 }
Exemplo n.º 10
0
        // GET: BookmarkEntities/Edit/5
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

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

            if (bookmarkEntity == null)
            {
                return(NotFound());
            }
            ViewBag.Types = BookmarkEntity.GetTypeAsSelectList(bookmarkEntity.BookmarkType);
            return(toEdit(bookmarkEntity));
        }
Exemplo n.º 11
0
        public async Task <bool> AddAsync(BookmarkEntity entity)
        {
            await _dbContext.Bookmarks.AddAsync(entity);

            try
            {
                await _dbContext.SaveChangesAsync();

                return(true);
            }
            catch (Exception e)
            {
                _logger.LogError("Has Exception", e);
                return(false);
            }
        }
Exemplo n.º 12
0
        public IActionResult Create(BookmarkEntity.Type BookmarkType, string ParentPath, string returnUrl)
        {
            if (ParentPath == null)
            {
                return(View("Error", new ErrorViewModel()));
            }

            ViewBag.returnUrl = returnUrl;
            ViewBag.Types     = BookmarkEntity.Gettypes();

            switch (BookmarkType)
            {
            case BookmarkEntity.Type.FOLDER:
            {
                return(View("Folder/CreateFolder", new Folder {
                        ParentPath = ParentPath
                    }));
            }

            case BookmarkEntity.Type.LINK:
            {
                return(View("Link/CreateLink", new ItemLink {
                        ParentPath = ParentPath
                    }));
            }

            case BookmarkEntity.Type.LOCATION:
            {
                return(View("Location/CreateLocation", new ItemLocation {
                        ParentPath = ParentPath
                    }));
            }

            case BookmarkEntity.Type.TEXTFILE:
            {
                return(View("Textfile/CreateTextfile", new ItemTextFile {
                        ParentPath = ParentPath
                    }));
            }

            default:
            {
                ViewBag.Path = GetAllPossiblePath();
                return(View("Create"));
            }
            }
        }
Exemplo n.º 13
0
        public IActionResult EditFromPath(string Parent, string returnUrl)
        {
            if (Parent == null)
            {
                return(NotFound());
            }

            Tuple <string, string> tuple = GetFolderAndParentFolder(Parent.Replace("item-", "").Replace("-", "|"));
            var bookmark = bookmarkEntityRepo.GetBookMarkByNameAndParentPath(tuple.Item1, tuple.Item2);

            if (bookmark == null)
            {
                return(NotFound());
            }
            ViewBag.returnUrl = returnUrl;
            ViewBag.Types     = BookmarkEntity.GetTypeAsSelectList(bookmark.BookmarkType);
            return(toEdit(bookmark));
        }
Exemplo n.º 14
0
        public async Task <IActionResult> CreateFolder([Bind("Id,Name,ReadOnly,ParentPath")]
                                                       Folder folder, string returnUrl)
        {
            BookmarkEntity parent = folderRepo.GetById((Convert.ToInt32(folder.ParentPath)));

            if (folder.ParentPath.Equals("-1"))
            {
                folder.ParentPath = "Root";
            }
            else
            {
                folder.ParentPath = parent.ToString().Replace("Root/", "").Replace("/", "|");
            }

            if (ModelState.IsValid)
            {
                if (parent != null && parent.ReadOnly)
                {
                    return(View("Error", new ErrorViewModel("Parent folder is not Editable!", "\'" + folder.ParentPath + "\' is readonly")));
                }

                if (bookmarkEntityRepo.NameExistById(folder.Name, folder.ParentPath, folder.Id))
                {
                    return(View("Error", new ErrorViewModel("Folder already exist!", "A folder with name \'" + folder.Name + "\' already exist at \'" + folder.ParentPath + "\'")));
                }
                folderRepo.InsertAsync(folder);
                await _context.SaveChangesAsync();

                if (returnUrl != null && returnUrl.Equals("Home"))
                {
                    return(Redirect("/Home"));
                }
                else if (returnUrl == null)
                {
                    return(Redirect("/BookmarkEntities"));
                }
                else
                {
                    return(Redirect(returnUrl));
                }
            }
            return(View(folder));
        }
Exemplo n.º 15
0
        public async Task <IActionResult> CreateTextfile([Bind("Id,Title, Uri, Content, Name, ReadOnly,ParentPath")]
                                                         ItemTextFile file, string returnUrl)
        {
            BookmarkEntity parent = folderRepo.GetById((Convert.ToInt32(file.ParentPath)));

            if (file.ParentPath.Equals("-1"))
            {
                file.ParentPath = "Root";
            }
            else
            {
                if (parent == null)
                {
                    return(NotFound());
                }
                file.ParentPath = parent.ToString().Replace("/", "|");
            }

            if (ModelState.IsValid)
            {
                if (parent.ReadOnly)
                {
                    return(View("Error", new ErrorViewModel("Parent folder is not Editable!", "\'" + file.ParentPath + "\' is readonly")));
                }
                if (bookmarkEntityRepo.NameExistById(file.Name, file.ParentPath, file.Id))
                {
                    return(View("Error", new ErrorViewModel()));
                }
                itemTextfileRepo.InsertAsync(file);
                await _context.SaveChangesAsync();

                if (returnUrl != null && returnUrl.Equals("Home"))
                {
                    return(Redirect("/Home"));
                }
                else
                {
                    return(Redirect("/BookmarkEntities"));
                }
            }
            return(View(file));
        }
Exemplo n.º 16
0
        private IActionResult toDetails(BookmarkEntity bookmarkEntity)
        {
            switch (bookmarkEntity.BookmarkType)
            {
            case BookmarkEntity.Type.FOLDER:
            {
                if (bookmarkEntity.ParentPath == null || bookmarkEntity.ParentPath.Equals("") || bookmarkEntity.ParentPath.Equals("Root"))
                {
                    ViewBag.DirectChild   = bookmarkEntityRepo.NumberOfDirectItems(bookmarkEntity.Name);
                    ViewBag.IndirectChild = bookmarkEntityRepo.NumberOfIndirectItems(bookmarkEntity.Name);
                }
                else
                {
                    ViewBag.DirectChild   = bookmarkEntityRepo.NumberOfDirectItems(bookmarkEntity.ParentPath + "|" + bookmarkEntity.Name);
                    ViewBag.IndirectChild = bookmarkEntityRepo.NumberOfIndirectItems(bookmarkEntity.ParentPath + "|" + bookmarkEntity.Name);
                }

                return(View("Folder/Details", bookmarkEntity));
            }

            case BookmarkEntity.Type.LINK:
            {
                return(View("Link/Details", bookmarkEntity));
            }

            case BookmarkEntity.Type.LOCATION:
            {
                return(View("Location/Details", bookmarkEntity));
            }

            case BookmarkEntity.Type.TEXTFILE:
            {
                return(View("Textfile/Details", bookmarkEntity));
            }

            default:
            {
                return(View("Details"));
            }
            }
        }
Exemplo n.º 17
0
        private IActionResult toDelete(BookmarkEntity bookmarkEntity)
        {
            if (bookmarkEntity.ReadOnly)
            {
                return(View("Error", new ErrorViewModel("Item Readonly!", "\'" + bookmarkEntity.Name + "\' is readonly, therefor it cannot be deleted.")));
            }
            switch (bookmarkEntity.BookmarkType)
            {
            case BookmarkEntity.Type.FOLDER:
            {
                ViewBag.DirectChild   = bookmarkEntityRepo.NumberOfDirectItems(bookmarkEntity.ToString().Replace("/", "|"));
                ViewBag.IndirectChild = bookmarkEntityRepo.NumberOfIndirectItems(bookmarkEntity.ToString().Replace("/", "|"));
                return(View("Folder/Delete", bookmarkEntity));
            }

            case BookmarkEntity.Type.LINK:
            {
                return(View("Link/Delete", bookmarkEntity));
            }

            case BookmarkEntity.Type.LOCATION:
            {
                return(View("Location/Delete", bookmarkEntity));
            }

            case BookmarkEntity.Type.TEXTFILE:
            {
                return(View("Textfile/Delete", bookmarkEntity));
            }

            default:
            {
                return(View("Edit"));
            }
            }
        }
Exemplo n.º 18
0
        /// <summary>Creates a new, empty BookmarkEntity object.</summary>
        /// <returns>A new, empty BookmarkEntity object.</returns>
        public override IEntity Create()
        {
            IEntity toReturn = new BookmarkEntity();

            // __LLBLGENPRO_USER_CODE_REGION_START CreateNewBookmark
            // __LLBLGENPRO_USER_CODE_REGION_END
            return toReturn;
        }
Exemplo n.º 19
0
 public override Task <BookmarkEntity> Create(BookmarkEntity item)
 {
     throw new Exception("error!");
 }
Exemplo n.º 20
0
 /// <summary>
 /// Adds the thread to bookmarks.
 /// </summary>
 /// <param name="userID">User ID.</param>
 /// <param name="threadID">Thread ID.</param>
 /// <returns>true if save succeeded, false otherwise</returns>
 public static bool AddThreadToBookmarks(int userID, int threadID)
 {
     BookmarkEntity newBookmark = new BookmarkEntity();
     newBookmark.UserID = userID;
     newBookmark.ThreadID = threadID;
     return newBookmark.Save();
 }
Exemplo n.º 21
0
 public virtual Task <BookmarkEntity> Create(BookmarkEntity item)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 22
0
 public virtual Task <bool> Delete(BookmarkEntity item)
 {
     throw new NotImplementedException();
 }