Exemple #1
0
 protected void Create_Click(object sender, EventArgs e)
 {
     var context = new ApplicationDbContext();
     var content = this.postContentBox.Text;
     var post = new Post() { Content = content };
     context.Posts.Add(post);
     context.SaveChanges();
     Response.Redirect("~/Post.aspx");
 }
        protected void ButtonAddNewPost_Click(object sender, EventArgs e)
        {
            string currentUserName = Context.User.Identity.Name;
            string postText = this.TextBoxAddPost.Text;

            var newPost = new Post() { Author = currentUserName, PostText = postText };

            using (var db = new ApplicationDbContext())
            {
                db.Posts.Add(newPost);
                db.SaveChanges();

                this.GridViewPosts.DataSource = db.Posts.ToList();
                this.GridViewPosts.DataBind();
            }

            this.TextBoxAddPost.Text = "";
        }