Exemplo n.º 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");
 }
Exemplo n.º 2
0
        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 = "";
        }