Beispiel #1
0
        private TableRow CreateMessageRow(Message message)
        {
            var row = new TableRow();
            var titleCell = new TableCell
            {
                Text = HttpUtility.HtmlEncode(message.Title)
            };
            var viewsCell = new TableCell
            {
                Text = HttpUtility.HtmlEncode(message.Views.ToString())
            };
            var createdOnCell = new TableCell
            {
                Text = HttpUtility.HtmlEncode(message.CreatedOn.ToShortDateString())
            };
            row.Cells.Add(titleCell);
            row.Cells.Add(viewsCell);
            row.Cells.Add(createdOnCell);

            return row;
        }
Beispiel #2
0
        protected void Post_Click(object sender, EventArgs e)
        {
            using (var dbContext = new MessagesContext())
            {
                int id = 0;
                if (dbContext.Messages.Count != 0)
                {
                    id = dbContext.Messages.OrderByDescending(i => i.Id).First().Id++;
                }

                var message = new Message
                {
                    Id = id,
                    Title = MessageTitle.Text,
                    Views = 0,
                    CreatedOn = DateTime.Now
                };

                dbContext.Messages.Add(message);
                MessagesList.Rows.AddAt(1, CreateMessageRow(message));
            }
        }