コード例 #1
0
 protected void SaveMessage_Click(object sender, EventArgs e)
 {
     var db = new ChatDbContext();
     var item = new Message();
     item.CreationDate = DateTime.Now;
     item.UserId = this.User.Identity.GetUserId();
     item.Content = this.Content.Text;
     db.Messages.Add(item);
     db.SaveChanges();
     this.Content.Text = string.Empty;
     lvMessages.DataBind();
 }
コード例 #2
0
 public void lvMessages_InsertItem()
 {
     var db = new ChatDbContext();
     var item = new Message();
     TryUpdateModel(item);
     if (ModelState.IsValid)
     {
         item.CreationDate = DateTime.Now;
         db.Messages.Add(item);
         db.SaveChanges();
     }
 }
コード例 #3
0
        public void MessagesListView_InsertItem()
        {
            var item = new Message();
            TryUpdateModel(item);
            item.CreationDate = DateTime.Now;
            item.UserId = this.User.Identity.GetUserId();

            if (ModelState.IsValid)
            {
                var db = new ChatDbContext();
                db.Messages.Add(item);
                db.SaveChanges();
            }
        }