protected void ButtonNewBookmark_Click(object sender, EventArgs e) { Page.Validate(); if (!Page.IsValid) { for (int i = 0; i < Page.Validators.Count; i++) { var validator = Page.Validators[i]; if (!validator.IsValid) { ErrorSuccessNotifier.AddErrorMessage(validator.ErrorMessage); } } return; } ExecuteAndHandleErrors(() => { string title = this.TextBoxNewBookmarkTitle.Text; string url = this.TextBoxNewBookmarkUrl.Text; Bookmark newBookmark = new Bookmark(); newBookmark.Title = title; newBookmark.URL = url; newBookmark.CreationDate = DateTime.Now; BookmarksEntities context = new BookmarksEntities(); string currentUserName = User.Identity.Name.ToLowerInvariant(); var userId = (from u in context.aspnet_Users where u.UserName == currentUserName select u.UserId).First(); newBookmark.UserID = userId; context.AddToBookmarks(newBookmark); context.SaveChanges(); }); }
/// <summary> /// Create a new Bookmark object. /// </summary> /// <param name="bookmarkID">Initial value of the BookmarkID property.</param> /// <param name="title">Initial value of the Title property.</param> /// <param name="uRL">Initial value of the URL property.</param> /// <param name="creationDate">Initial value of the CreationDate property.</param> /// <param name="userID">Initial value of the UserID property.</param> public static Bookmark CreateBookmark(global::System.Int32 bookmarkID, global::System.String title, global::System.String uRL, global::System.DateTime creationDate, global::System.Guid userID) { Bookmark bookmark = new Bookmark(); bookmark.BookmarkID = bookmarkID; bookmark.Title = title; bookmark.URL = uRL; bookmark.CreationDate = creationDate; bookmark.UserID = userID; return bookmark; }
/// <summary> /// Deprecated Method for adding a new object to the Bookmarks EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToBookmarks(Bookmark bookmark) { base.AddObject("Bookmarks", bookmark); }