protected void Page_Load(object sender, EventArgs e) { using (var db = new NoteContext()) { Notes = db.Notes.ToList(); } }
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"); }
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"); } } }