示例#1
0
 protected void TimerTimeRefresh_Tick(object sender, EventArgs e)
 {
     System.Threading.Thread.Sleep(3000);
     var context = new ChatContext();
     var messages = context.Messages.OrderByDescending(c => c.Date).Take(100).ToList();
     this.MessagesGrid.DataSource = messages;
     this.MessagesGrid.DataBind();
 }
示例#2
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!Page.IsPostBack)
     {
         var context = new ChatContext();
         var messages = context.Messages.OrderByDescending(c => c.Date).Take(100).ToList();
         this.MessagesGrid.DataSource = messages;
         this.MessagesGrid.DataBind();
     }
 }
示例#3
0
        protected void ButtonPostMessage_Click(object sender, EventArgs e)
        {
            System.Threading.Thread.Sleep(3000);
            var context = new ChatContext();
            var messageToAdd = new Message();
            if (MessageTextInput.Text == string.Empty)
            {
                return;
            }

            messageToAdd.MessageText = this.MessageTextInput.Text;
            messageToAdd.Date = DateTime.Now;
            context.Messages.Add(messageToAdd);
            context.SaveChanges();

            var messages = context.Messages.OrderByDescending(c => c.Date).Take(100).ToList();
            this.MessagesGrid.DataSource = messages;
            this.MessagesGrid.DataBind();
        }