public void InsertComment(int id) { GalleryEntities context = new GalleryEntities(); Comment comment = new Comment(); comment.CreateTS = DateTime.Now; comment.Imgtext = txtComment.Text; comment.ImageSize = fplFileUpload.FileBytes.Length; comment.ImageID = id; context.Comment.Add(comment); context.SaveChanges(); }
protected void btnEditComment_Click(object sender, EventArgs e) { lblMessage.Text = ""; string ID = Request.QueryString["ID"]; int commentID = int.Parse(ID); GalleryEntities context = new GalleryEntities(); var comment = new Comment(); comment.Imgtext = txtComment.Text; comment.ID = commentID; context.Comment.Attach(comment); var entry = context.Entry(comment); entry.Property(c => c.Imgtext).IsModified = true; entry.Property(c => c.ID).IsModified = false; context.SaveChanges(); lblMessage.Text = "Save changes"; }