상속: IDisposable
예제 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            HttpCookie cookie = new HttpCookie("SecretInformation", "likeOMGMegan");
            HttpContext.Current.Response.Cookies.Add(cookie);

            using (var dbContext = new MessagesContext())
            {
                foreach (var message in dbContext.Messages.OrderByDescending(m => m.CreatedOn))
                {
                    MessagesList.Rows.Add(CreateMessageRow(message));
                }
            }
        }
예제 #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));
            }
        }