private void Button_Click_1(object sender, RoutedEventArgs e)//добавить { int sz = 0; int.TryParse(sizefield.Text, out sz); string authcode = ""; using (Model1 db = new Model1()) { var auth = db.authors; foreach (authors a in auth) { if (a.ToString() == authList.SelectedValue.ToString()) { authcode = a.authornamecode; } } } book bk = new book(booknamefield.Text, sz, authcode); using (LibruaryContext db = new LibruaryContext()) { db.books.Add(bk); db.SaveChanges(); } selectALL(); }
private void Button_Click(object sender, RoutedEventArgs e)//удалить { if (view.SelectedIndex > -1) { string selected = view.SelectedItem.ToString(); using (LibruaryContext db = new LibruaryContext()) { var bok = db.books; foreach (book b in bok) { if (b.ToString() == selected) { db.books.Remove(b); } } db.SaveChanges(); } selectALL(); } }
public void Save() { db.SaveChanges(); }