public void TestEditBatchNotes() { UserProfile jon = TestUtils.createUser(111, "Jon", "Smith"); Batch batch = TestUtils.createBatch("Test", BatchType.Beer, jon); BatchNote note = TestUtils.createBatchNote(batch, "Test Note", "I am a note!", jon); BrewersBuddyContext db = new BrewersBuddyContext(); var id = note.NoteId; var note1 = db.BatchNotes.Find(id); Assert.IsTrue(batch.Notes.Contains(note)); Assert.AreEqual("Test Note", note1.Title); Assert.AreEqual("I am a note!", note1.Text); note.Title = "Test Title"; // save changes db = new BrewersBuddyContext(); db.Entry(note).State = System.Data.EntityState.Modified; db.SaveChanges(); //clear context and reload db = new BrewersBuddyContext(); note1 = db.BatchNotes.Find(id); // verify local context is not being used note.Text = "test text"; Assert.AreEqual("Test Title", note1.Title); Assert.AreEqual("I am a note!", note1.Text); }
public ActionResult EditNote(BatchNote note) { if (ModelState.IsValid) { BrewersBuddyContext db2 = new BrewersBuddyContext(); db2.Entry(note).State = EntityState.Modified; db2.SaveChanges(); //Associate the batch with the note int batchId = (int)Session["CurrentBatchId"]; return RedirectToAction("Details/" + batchId); } return View(note); }