public IActionResult Index() { GuestBookDataContext db = new GuestBookDataContext(); var items = db.GuestBooks.ToList(); return(View(items)); }
public IActionResult Create(GuestBook item) { if (ModelState.IsValid) { GuestBookDataContext db = new GuestBookDataContext(); db.Add(item); db.SaveChanges(); return(RedirectToAction("Index")); } return(View()); }
private void buttonInsertData_Click(object sender, EventArgs e) { var name = textBoxName.Text; var email = textBoxEmail.Text; var message = textBoxMessage.Text; try { var db = new GuestBookDataContext(); var item = new GuestBook { Name = name, Email = email, Message = message }; db.GuestBook.Add(item); db.SaveChanges(); MessageBox.Show("Data berhasil disimpan."); } catch (Exception ex) { MessageBox.Show("Data gagal disimpan. \n" + ex.ToString()); } }
public HomeController(GuestBookDataContext context) { db = context; }