Inheritance: DbContext
Exemple #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     using (var db = new NoteContext())
     {
         Notes = db.Notes.ToList();
     }
 }
Exemple #2
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Request.Form.AllKeys.Contains("title"))
     {
         using (var db = new NoteContext())
         {
             var note = new Note
             {
                 Title     = Request.Form["title"],
                 Body      = Request.Form["body"],
                 TimeStamp = Request.Form["timestamp"],
                 Created   = DateTime.Now
             };
             db.Notes.Add(note);
             db.SaveChanges();
         }
     }
     Response.Redirect("Default.aspx");
 }
Exemple #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var noteId = int.Parse(Request.QueryString["id"]);

            using (var db = new NoteContext())
            {
                noteInstance = db.Notes.First(n => n.Id == noteId);
                if (IsPostBack)
                {
                    noteInstance.Title     = Request.Form["title"];
                    noteInstance.Body      = Request.Form["body"];
                    noteInstance.TimeStamp = Request.Form["timestamp"];

                    db.Entry(noteInstance).State = EntityState.Modified;
                    db.SaveChanges();
                    Response.Redirect("Default.aspx");
                }
            }
        }