Пример #1
0
        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();
        }
Пример #2
0
 private void selectALL()
 {
     view.Items.Clear();
     using (LibruaryContext db = new LibruaryContext())
     {
         var bok = db.books;
         foreach (book b in bok)
         {
             view.Items.Add(b);
         }
     }
 }
Пример #3
0
 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();
     }
 }
Пример #4
0
        private void Button_Click_2(object sender, RoutedEventArgs e)//find
        {
            string bookname = FBN.Text;

            using (LibruaryContext db = new LibruaryContext())
            {
                var b = from d in db.books where d.bookname == bookname select d;
                if (b.Count() > 0)
                {
                    foreach (book eachb in b)
                    {
                        MessageBox.Show(eachb.ToString());
                    }
                }
                else
                {
                    MessageBox.Show("ничего не найдено");
                }
            }
        }
Пример #5
0
 public BookRepository(LibruaryContext context)
 {
     this.db = context;
 }