private void RentedBooksGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)//laenatud raamatu info
 {
     if (RentedBooksGrid.SelectedItems != null)
     {
         for (int i = 0; i < RentedBooksGrid.SelectedItems.Count; i++)
         {
             RentedBooksInfo info = RentedBooksGrid.SelectedItems[i] as RentedBooksInfo;
             if (info != null)
             {
                 var g = db.RentedBooksInfo.
                         Where(t => t.BookId == info.Book_Id).ToList();
                 foreach (RentedBooksInfo r in g)
                 {
                     RentInfoTextBlock.Text = "Return Date: " + r.Return_date + "\r\nRent Date: "
                                              + r.Rent_date + "\r\nStatus: " + r.Status;
                     Calendar.SelectedDate = r.Return_date;
                 }
             }
         }
     }
 }
        private void ReturnBtn_Click(object sender, RoutedEventArgs e)//return nupp
        {
            RentInfoTextBlock.Text = String.Empty;
            if (RentedBooksGrid.SelectedItems != null)
            {
                for (int i = 0; i < RentedBooksGrid.SelectedItems.Count; i++)
                {
                    RentedBooksInfo rbook = RentedBooksGrid.SelectedItems[i] as RentedBooksInfo;
                    if (rbook != null)
                    {
                        Rent r = (from p in db.Rent
                                  where p.Book_Id == rbook.BookId &&
                                  p.User_Id == rbook.User_Id &&
                                  p.RentId == rbook.RentId
                                  select p).SingleOrDefault();

                        Book b = (from p in db.Book
                                  where p.BookId == rbook.BookId
                                  select p).SingleOrDefault();
                        b.Quantity++;
                        db.Rent.Remove(r);
                        db.SaveChanges();
                    }
                }
            }

            LibraryEntities db2 = new LibraryEntities();

            db2.Book.Load();
            db2.RentedBooksInfo.Load();
            BooksDataGrid.ItemsSource   = null;
            RentedBooksGrid.ItemsSource = null;
            BooksDataGrid.ItemsSource   = db2.Book.Local.ToBindingList();
            var g = db2.RentedBooksInfo.
                    Where(t => t.UserId == SignUp.userid).ToList();

            RentedBooksGrid.ItemsSource = g;
            db2.Dispose();
        }