Example #1
0
        protected void ButtonSendMessage_Click(object sender, EventArgs e)
        {
            if (!IsValid)
            {
                return;
            }

            string contents = this.TextBoxContents.Text.Trim();
            string author = this.TextBoxAuthor.Text.Trim();

            if (contents.Length > 250)
            {
                this.LabelErrorMessage.Text = "The contents must be at most 250 characters long.";
                return;
            }

            if (author.Length > 50)
            {
                this.LabelErrorMessage.Text = "The author name must be at most 50 characters long.";
                return;
            }

            var context = new SimpleChatEntities();

            var message = new Message
            {
                Contents = this.TextBoxContents.Text,
                Author = this.TextBoxAuthor.Text,
                Timestamp = DateTime.Now
            };

            context.Messages.Add(message);
            context.SaveChanges();

            this.TextBoxContents.Text = string.Empty;
            this.TextBoxAuthor.Text = string.Empty;
        }
Example #2
0
        protected void ButtonSendMessage_Click(object sender, EventArgs e)
        {
            if (!IsValid)
            {
                return;
            }

            string contents = this.TextBoxContents.Text.Trim();
            string author   = this.TextBoxAuthor.Text.Trim();

            if (contents.Length > 250)
            {
                this.LabelErrorMessage.Text = "The contents must be at most 250 characters long.";
                return;
            }

            if (author.Length > 50)
            {
                this.LabelErrorMessage.Text = "The author name must be at most 50 characters long.";
                return;
            }

            var context = new SimpleChatEntities();

            var message = new Message
            {
                Contents  = this.TextBoxContents.Text,
                Author    = this.TextBoxAuthor.Text,
                Timestamp = DateTime.Now
            };

            context.Messages.Add(message);
            context.SaveChanges();

            this.TextBoxContents.Text = string.Empty;
            this.TextBoxAuthor.Text   = string.Empty;
        }