protected void Page_Load(object sender, EventArgs e)
 {
     BookmarksEntities context = new BookmarksEntities();
     var bookmarks = context.Bookmarks.Take(5);
     this.ListViewBookmarks.DataSource = bookmarks.ToList();
     this.DataBind();
 }
        // The id parameter name should match the DataKeyNames value set on the control
        public void GridViewBookmarks_DeleteItem(int bookmarkId)
        {
            BookmarksEntities context = new BookmarksEntities();
            Bookmark bookmark = context.Bookmarks.Find(bookmarkId);

            context.Bookmarks.Remove(bookmark);
            context.SaveChanges();
            ErrorSuccessNotifier.AddInfoMessage("Bookmark successfully deleted.");
            this.GridViewBookmarks.PageIndex = 0;
            
        }
 protected void Page_PreRender(object sender, EventArgs e)
 {
     if (!isNewBookmark)
     {
         using (BookmarksEntities context = new BookmarksEntities())
         {
             Bookmark bookmark = context.Bookmarks.Find(bookmarkId);
             this.TextBoxBookmarkTitle.Text = bookmark.Title;
             this.TextBoxBookmarkURL.Text = bookmark.URL;
         }
     }
 }
        protected void LinkButtonSaveBookmark_Click(object sender, EventArgs e)
        {
            using (BookmarksEntities context = new BookmarksEntities())
            {
                Bookmark bookmark;
                if (isNewBookmark)
                {
                    bookmark = new Bookmark();
                    context.Bookmarks.Add(bookmark);
                }
                else
                {
                    bookmark = context.Bookmarks.Find(this.bookmarkId);
                }

                try
                {
                    bookmark.Title = this.TextBoxBookmarkTitle.Text;
                    bookmark.URL = this.TextBoxBookmarkURL.Text;
                    bookmark.DateOfCreation = DateTime.Now;

                    context.SaveChanges();

                    ErrorSuccessNotifier.AddInfoMessage("Bookmark " + (this.isNewBookmark ? "created." : "edited."));

                    ErrorSuccessNotifier.ShowAfterRedirect = true;
                    Response.Redirect("EditBookmarks.aspx", false);


                }
                catch (Exception ex)
                {
                    ErrorSuccessNotifier.AddErrorMessage(ex);
                }
            }
        }
 public IQueryable<Bookmark> GridViewBookmarks_GetData()
 {
     BookmarksEntities context = new BookmarksEntities();
     return context.Bookmarks.OrderByDescending(b => b.DateOfCreation);
 }