Exemplo n.º 1
0
 protected void btnDelte_Click(object sender, EventArgs e)
 {
     int.TryParse(bookmarkId.Value, out int id);
     BookmarkRepo.DeleteBookmark(id);
     Callback("Successfully unsaved", false);
     //Response.Redirect($"/users/{Page.RouteData.Values["Id"].ToString()}/bookmarks/");
 }
Exemplo n.º 2
0
        /// <summary>
        /// Render the list of bookmarks into the placeholder
        /// </summary>
        /// <param name="message">message to be display after rerender the list of bookmarks</param>
        /// <param name="err">indicate if message is an error message or not</param>
        public void Refresh(string message, bool err)
        {
            bookmarks = BookmarkRepo.GetBookmarks(UserId, "DESC");
            Render();
            string e      = err ? "true" : "false";
            string script = $"<script>displayAlert('{message}',{e});</script>";

            Page.ClientScript.RegisterStartupScript(Page.GetType(), "Javascript", script);
        }
Exemplo n.º 3
0
        public BookmarkInfo(string Name, User user)
        {
            this.InfoType = "BookmarkInfo";
            Bookmark bookmark = new BookmarkRepo().GetBookmark(Name, user);

            this.ID     = bookmark.ID;
            this.Name   = bookmark.Name;
            this.Global = bookmark.Global;
        }
        /**
         * Command actions
         */
        public void SaveBookmark(object input)
        {
            try
            {
                BookmarkRepo bookmarkRepo = new BookmarkRepo();

                // 0. Get old bookmark name
                _name = bookmarkRepo.GetBookmarkNameWithId(Bookmark.ID);

                // 1. Update new values to database
                bookmarkRepo.UpdateBookmark(Bookmark);

                // 1.1 Track bookmark update
                BookmarkInfo info = new BookmarkInfo(Bookmark.Name, User);
                new Tracker(User).TrackUpdate <BookmarkInfo>(info, _name);
            }
            catch (Exception e)
            {
                // Message = "constraint failed\r\nUNIQUE constraint failed: tblBookmark.Name, tblBookmark.UserID"}	System.Exception {System.Data.SQLite.SQLiteException}
                if (e.Message.Contains("UNIQUE"))
                {
                    if (
                        _dialogService.OpenDialog(new DialogYesNoViewModel("Bookmark with that name already exists, do you want to merge?", "Merge reference", DialogType.Question))
                        )
                    {
                        BookmarkRepo   repo         = new BookmarkRepo();
                        Bookmark       bookmarkFrom = repo.GetBookmark(_name, User);
                        Bookmark       bookmarkInto = repo.GetBookmark(Bookmark.Name, User);
                        List <Article> articlesFrom = repo.LoadArticlesForBookmark(User, bookmarkFrom);
                        List <Article> articlesInto = repo.LoadArticlesForBookmark(User, bookmarkInto);

                        // 1. Get unique articles between 2 references
                        List <Article> uniques = articlesFrom.Where(art => !articlesInto.Exists(el => el.Title == art.Title)).ToList();

                        // 2. Add those articles into merged reference
                        repo.AddListOfArticlesToBookmark(bookmarkInto, uniques);

                        // 3. Delete old reference
                        repo.DeleteBookmark(bookmarkFrom);
                    }
                }
                else
                {
                    new BugTracker().Track("Bookmark Editor", "Save Bookmark", e.Message, e.StackTrace);
                    _dialogService.OpenDialog(new DialogOkViewModel("Something went wrong.", "Error", DialogType.Error));
                }
            }
            finally
            {
                // 2. Refresh collections in parent;
                _parent.PopulateBookmarks();

                // 3. Close window
                (input as ICommand).Execute(null);
            }
        }
Exemplo n.º 5
0
        protected void btnBookmark_Click(object sender, EventArgs e)
        {
            Bookmark bookmark = new Bookmark
            {
                PostId = Convert.ToInt32(postId.Value),
                UserId = Convert.ToInt32(Session["UserId"])
            };

            BookmarkRepo.CreateBookmark(bookmark);
            Page.ClientScript.RegisterStartupScript(Page.GetType(), "Javascript", "<script>displayAlert('Successfully Saved' ,false);</script>");
        }
Exemplo n.º 6
0
        /// <summary>
        /// Handle filter bookmarks event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnFilter_Click(object sender, EventArgs e)
        {
            string        orderBy = sortOpt.SelectedValue.Equals("New") ? "DESC" : "ASC";
            List <string> filters = new List <string>();

            if (cbReview.Checked)
            {
                filters.Add("'review'");
            }
            if (cbPublic.Checked)
            {
                filters.Add("'public'");
            }
            bookmarks = BookmarkRepo.GetBookmarks(UserId, orderBy);
            Render();
        }
        private async Task Populate(bool global)
        {
            List <Bookmark> bookmarks = new List <Bookmark>();
            BookmarkRepo    repo      = new BookmarkRepo();

            if (global)
            {
                await Task.Run(() =>
                {
                    // 3. Populate global bookmarks
                    foreach (Bookmark bookmark in (new BookmarkRepo()).LoadGlobalBookmarks())
                    {
                        //bookmark.PopulateArticles(User);
                        bookmark.GetArticleCount(User);
                        bookmarks.Add(bookmark);
                    }
                });

                foreach (Bookmark bookmark in bookmarks)
                {
                    GlobalBookmarks.Add(bookmark);
                }
            }
            else
            {
                await Task.Run(() =>
                {
                    // 2. Populate local bookmarks
                    foreach (Bookmark bookmark in repo.LoadBookmarks(User))
                    {
                        // Populate articles colletion for each bookmark
                        //bookmark.PopulateArticles(User);
                        bookmark.GetArticleCount(User);
                        bookmarks.Add(bookmark);
                    }
                });

                foreach (Bookmark bookmark in bookmarks)
                {
                    Bookmarks.Add(bookmark);
                }
            }
        }
        public async void AddArticlesToBookmark(object input)
        {
            try
            {
                // Close window
                (input as ICommand).Execute(null);

                _workStatus(true);

                await Task.Run(() =>
                {
                    BookmarkRepo repo = new BookmarkRepo();
                    foreach (Article article in _articles)
                    {
                        if (!repo.CheckArticleInBookmark(SelectedBookmark, article))
                        {
                            // 1. Add article to bookmark
                            repo.AddArticleToBookmark(SelectedBookmark, article);
                        }
                    }
                });

                _workStatus(false);

                _dialogService.OpenDialog(new DialogOkViewModel("Done", "Result", DialogType.Success));
            }
            catch (Exception e)
            {
                new BugTracker().Track("Mass Bookmark Manager", "Mass Bookmark", e.Message, e.StackTrace);
                _dialogService.OpenDialog(new DialogOkViewModel("Something went wrong.", "Error", DialogType.Error));
            }
            finally
            {
                _workStatus(false);
            }
        }
Exemplo n.º 9
0
 protected void Page_Load(object sender, EventArgs e)
 {
     this.Master.BookmarkPageBtn.CssClass = "user_right_navlink active";
     bookmarks = BookmarkRepo.GetBookmarks(UserId, "DESC");
     Render();
 }
Exemplo n.º 10
0
        public void Sync()
        {
            // 1. Sync information
            _logs.ForEach((log) =>
            {
                User user = new UserRepo().GetUserByName(log.Username);

                switch (log.Type)
                {
                case "Create":
                    // Create article
                    if (log.Info.InfoType == "ArticleInfo")
                    {
                        ArticleInfo local_info = log.Info as ArticleInfo;
                        Article article        = new Article(local_info);
                        ArticleRepo repo       = new ArticleRepo();

                        // Edge case: Article already exists
                        if (repo.GetArticleWithTitle(article.Title) != null)
                        {
                            string mismatch = $"Article '{local_info.Title}' already exists.";
                            _mismatches.Add(mismatch);
                            return;
                        }

                        // 1. Add article to database
                        repo.SaveArticle(article, user);

                        // 2. Copy file
                        string fileName = repo.GetFileWithTitle(local_info.Title);
                        File.Copy(
                            Path.Combine(_filesPath, local_info.FileName + ".pdf"),
                            Path.Combine(Path.Combine(Environment.CurrentDirectory, "Files"), fileName + ".pdf"));

                        Article dbArticle = repo.GetArticleWithTitle(local_info.Title);

                        // 3. Add references and bookmarks
                        BookmarkRepo bookmarkRepo   = new BookmarkRepo();
                        ReferenceRepo referenceRepo = new ReferenceRepo();

                        // Bookmarks
                        local_info.Bookmarks.ForEach((bookmark) =>
                        {
                            Bookmark dbBookmark = bookmarkRepo.GetBookmark(bookmark.Name, user);
                            bookmarkRepo.AddArticleToBookmark(dbBookmark, dbArticle);
                        });

                        // References
                        local_info.References.ForEach((reference) =>
                        {
                            Reference dbReference = referenceRepo.GetReference(reference.Name);
                            referenceRepo.AddArticleToReference(dbReference, dbArticle);
                        });
                    }
                    // Create bookmark
                    else if (log.Info.InfoType == "BookmarkInfo")
                    {
                        BookmarkInfo local_info = log.Info as BookmarkInfo;
                        BookmarkRepo repo       = new BookmarkRepo();

                        // Edge case: Bookmark already exists
                        if (repo.GetBookmark(local_info.Name, user) != null)
                        {
                            string mismatch = $"Bookmark '{local_info.Name}' already exists.";
                            _mismatches.Add(mismatch);
                            return;
                        }

                        repo.AddBookmark(local_info.Name, local_info.Global, user);
                    }
                    // Create reference
                    else if (log.Info.InfoType == "ReferenceInfo")
                    {
                        ReferenceInfo local_info = log.Info as ReferenceInfo;
                        ReferenceRepo repo       = new ReferenceRepo();

                        // Edge case: Reference already exists
                        if (repo.GetReference(local_info.Name) != null)
                        {
                            string mismatch = $"Reference '{local_info.Name}' already exists.";
                            _mismatches.Add(mismatch);
                            return;
                        }

                        new ReferenceRepo().AddReference(local_info.Name);
                    }
                    break;

                case "Update":
                    // Update article
                    if (log.Info.InfoType == "ArticleInfo")
                    {
                        ArticleInfo local_info  = (ArticleInfo)log.Info;
                        ArticleRepo repo        = new ArticleRepo();
                        Article existingArticle = repo.GetFullArticleWithTitle(user, log.Changed);

                        // Edge case: Article I am trying to update doesn't exist
                        if (existingArticle == null)
                        {
                            string mismatch = $"Article '{log.Changed}' doesn't exist and can't be updated.";
                            _mismatches.Add(mismatch);
                            return;
                        }

                        Article newArticle = new Article(local_info);
                        newArticle.ID      = existingArticle.ID;
                        repo.UpdateArticle(newArticle, user);
                    }
                    // Update bookmark
                    else if (log.Info.InfoType == "BookmarkInfo")
                    {
                        BookmarkInfo local_info   = (BookmarkInfo)log.Info;
                        BookmarkRepo repo         = new BookmarkRepo();
                        Bookmark existingBookmark = repo.GetBookmark(log.Changed, user);

                        // Edge case: Bookmark I am trying to update doesn't exist
                        if (existingBookmark == null)
                        {
                            string mismatch = $"Bookmark '{local_info.Name}' doesn't exist and can't be updated.";
                            _mismatches.Add(mismatch);
                            return;
                        }

                        Bookmark newBookmark = new Bookmark(local_info);
                        newBookmark.ID       = existingBookmark.ID;
                        repo.UpdateBookmark(newBookmark);
                    }
                    // Update reference
                    else if (log.Info.InfoType == "ReferenceInfo")
                    {
                        ReferenceInfo local_info    = (ReferenceInfo)log.Info;
                        ReferenceRepo repo          = new ReferenceRepo();
                        Reference existingReference = repo.GetReference(log.Changed);

                        // Edge case: Reference I am trying to update doesn't exist
                        if (existingReference == null)
                        {
                            string mismatch = $"Bookmark '{local_info.Name}' doesn't exist and can't be updated.";
                            _mismatches.Add(mismatch);
                            return;
                        }

                        Reference newReference = new Reference(local_info);
                        newReference.ID        = existingReference.ID;
                        if (local_info.Title != null)
                        {
                            newReference.ArticleID = (int)new ArticleRepo().GetArticleWithTitle(local_info.Title).ID;
                        }
                        repo.UpdateReference(newReference);
                    }
                    break;

                case "Coupling":
                    Couple info = (Couple)log.Info;
                    // Couple bookmark
                    if (info.CollectionType == "Bookmark")
                    {
                        BookmarkRepo bookmarkRepo = new BookmarkRepo();
                        ArticleRepo articleRepo   = new ArticleRepo();

                        Bookmark bookmark = bookmarkRepo.GetBookmark(info.Name, user);
                        Article article   = articleRepo.GetArticleWithTitle(info.Title);

                        // Edge case: Article or bookmark doesn't exist or Article is already in bookmark
                        if (bookmark == null)
                        {
                            string mismatch = $"Can't couple article - '{info.Title}' with bookmark '{info.Name}' because bookmark doesn't exist";
                            _mismatches.Add(mismatch);
                            return;
                        }
                        else if (article == null)
                        {
                            string mismatch = $"Can't couple article - '{info.Title}' with bookmark '{info.Name}' because article doesn't exist";
                            _mismatches.Add(mismatch);
                            return;
                        }

                        // Add
                        if (info.ActionType == "Add")
                        {
                            // Edge case: Article is already in bookmark
                            if (bookmarkRepo.CheckArticleInBookmark(bookmark, article))
                            {
                                string mismatch = $"Article - '{info.Title}' is already in bookmark '{info.Name}'";
                                _mismatches.Add(mismatch);
                                return;
                            }
                            bookmarkRepo.AddArticleToBookmark(bookmark, article);
                        }
                        // Remove
                        else if (info.ActionType == "Remove")
                        {
                            // Edge case: Article is not in bookmark
                            if (!bookmarkRepo.CheckArticleInBookmark(bookmark, article))
                            {
                                string mismatch = $"Article - '{info.Title}' can not be removed from bookmark '{info.Name}' (Its not there)";
                                _mismatches.Add(mismatch);
                                return;
                            }
                            bookmarkRepo.RemoveArticleFromBookmark(bookmark, article);
                        }
                    }
                    // Couple reference
                    else if (info.CollectionType == "Reference")
                    {
                        ReferenceRepo referenceRepo = new ReferenceRepo();
                        ArticleRepo articleRepo     = new ArticleRepo();

                        Reference reference = referenceRepo.GetReference(info.Name);
                        Article article     = articleRepo.GetArticleWithTitle(info.Title);

                        // Edge case: Article or bookmark doesn't exist
                        if (reference == null)
                        {
                            string mismatch = $"Can't couple article - '{info.Title}' with reference '{info.Name}' because reference doesn't exist";
                            _mismatches.Add(mismatch);
                            return;
                        }
                        else if (article == null)
                        {
                            string mismatch = $"Can't couple article - '{info.Title}' with reference '{info.Name}' because article doesn't exist";
                            _mismatches.Add(mismatch);
                            return;
                        }

                        // Add
                        if (info.ActionType == "Add")
                        {
                            if (referenceRepo.CheckArticleInReference(reference, article))
                            {
                                string mismatch = $"Article - '{info.Title}' is already in reference '{info.Name}'";
                                _mismatches.Add(mismatch);
                                return;
                            }
                            referenceRepo.AddArticleToReference(reference, article);
                        }
                        // Remove
                        else if (info.ActionType == "Remove")
                        {
                            if (!referenceRepo.CheckArticleInReference(reference, article))
                            {
                                string mismatch = $"Article - '{info.Title}' is already in bookmark '{info.Name}'";
                                _mismatches.Add(mismatch);
                                return;
                            }
                            referenceRepo.RemoveArticleFromReference(reference, article);
                        }
                    }
                    break;

                case "Delete":
                    DeleteInfo local_info1 = (DeleteInfo)log.Info;
                    // Delete article
                    if (local_info1.ObjectType == "Article")
                    {
                        ArticleRepo repo = new ArticleRepo();
                        Article article  = repo.GetArticleWithTitle(local_info1.Name);

                        // Edge case: Article I am trying to delete doesn't exist
                        if (article == null)
                        {
                            string mismatch = $"Can't delete article '{local_info1.Name}' because it doesn't exist";
                            _mismatches.Add(mismatch);
                            return;
                        }

                        string file = repo.GetFileWithTitle(local_info1.Name);
                        repo.DeleteArticle(article);
                        File.Delete(Path.Combine(Environment.CurrentDirectory, "Files", file + ".pdf"));
                    }
                    // Delete bookmark
                    else if (local_info1.ObjectType == "Bookmark")
                    {
                        BookmarkRepo repo = new BookmarkRepo();
                        Bookmark bookmark = repo.GetBookmark(local_info1.Name, user);

                        // Edge case: Bookmark I am trying to delete doesn't exist
                        if (bookmark == null)
                        {
                            string mismatch = $"Can't delete bookmark '{local_info1.Name}' because it doesn't exist";
                            _mismatches.Add(mismatch);
                            return;
                        }

                        repo.DeleteBookmark(bookmark);
                    }
                    // Delete reference
                    else if (local_info1.ObjectType == "Reference")
                    {
                        ReferenceRepo repo  = new ReferenceRepo();
                        Reference reference = repo.GetReference(local_info1.Name);

                        // Edge case: Reference I am trying to delete doesn't exist
                        if (reference == null)
                        {
                            string mismatch = $"Can't delete reference '{local_info1.Name}' because it doesn't exist";
                            _mismatches.Add(mismatch);
                            return;
                        }

                        repo.DeleteReference(reference);
                    }
                    break;

                case "Personal":
                    PersonalInfo local_info2 = (PersonalInfo)log.Info;
                    ArticleRepo repo1        = new ArticleRepo();
                    Article article3         = repo1.GetArticleWithTitle(local_info2.Title);

                    // Edge case: Article I am trying to add personal doesn't exist
                    if (article3 == null)
                    {
                        string mismatch = $"Can't add personal to article '{local_info2.Title}' because it doesn't exist";
                        _mismatches.Add(mismatch);
                        return;
                    }

                    article3.PersonalComment = local_info2.PersonalComment;
                    article3.SIC             = local_info2.SIC;

                    repo1.UpdatePersonal(article3, user);
                    break;

                case "Pending":
                    PendingInfo l_info = (PendingInfo)log.Info;

                    // 1. Remove pending section status from db
                    new GlobalRepo().RemovePending(l_info.Section);

                    // 2. Remove section from json
                    string path            = Path.Combine(Environment.CurrentDirectory, "sections.json");
                    string textInfo        = File.ReadAllText(path);
                    List <string> sections = JsonConvert.DeserializeObject <List <string> >(textInfo);
                    sections.Remove(l_info.Section);
                    textInfo = JsonConvert.SerializeObject(sections);
                    File.WriteAllText(path, textInfo);
                    break;

                default:
                    break;
                }
            });

            // 2. Write mismatches
            WriteMismatches();
        }