private void TakeBack_Click(object sender, RoutedEventArgs e) { string bookName = BookName.Text.ToString(); using (LibraryDbEntities books = new LibraryDbEntities()) { Table book = books.Tables.FirstOrDefault(x => x.BookName == bookName); TakeBack.Content = "Return the book to the library"; book.GivenTo = ""; books.SaveChanges(); Result.Text = $"Place in Library: {book.PlaceInLibrary}"; } }
private void Button1_Click(object sender, RoutedEventArgs e) { string bookName = BookName.Text.ToString(); using (LibraryDbEntities books = new LibraryDbEntities()) { Table book = books.Tables.FirstOrDefault(x => x.BookName == bookName); string giveTo = GiveTo.Text.ToString(); book.GivenTo = giveTo; books.SaveChanges(); GiveTo.Text = string.Empty; Result.Text = $"Place in Library: {book.PlaceInLibrary}" + Environment.NewLine + $"Given to: {book.GivenTo}"; GiveButton.Content = string.Empty; } }
private void Button_Click(object sender, RoutedEventArgs e) { string bookName = BookName.Text.ToString(); using (LibraryDbEntities books = new LibraryDbEntities()) { Table book = books.Tables.FirstOrDefault(x => x.BookName == bookName); string result = string.Empty; if (book != null) { if (book.GivenTo != "") { result = $"Place in Library: {book.PlaceInLibrary}" + Environment.NewLine + $"Given to: {book.GivenTo}"; TakeBack.Visibility = Visibility.Visible; TakeBack.Content = "Return the book to the library"; } else { result = $"Place in Library: {book.PlaceInLibrary}"; GiveTo.Text = "Give the book to"; GiveButton.Visibility = Visibility.Visible; GiveButton.Content = "Give"; } } else { result = "A book with that name does not exist!"; } Result.Text = result; } }
private void Button_Click(object sender, RoutedEventArgs e) { string authorName = string.Empty; string givenTo = string.Empty; var bookName = nameBox.Text.ToString(); if (nameBox.ToString() != null) { authorName = authorBox.Text.ToString(); } var placeInLibrary = placeBox.Text.ToString(); if (givenBox.ToString() != null) { givenTo = givenBox.Text.ToString(); } using (LibraryDbEntities books = new LibraryDbEntities()) { if (bookName == "" || placeInLibrary == "") { MessageBox.Show("You have to type the name of the book and it's place in the library", "Error", MessageBoxButton.OK); InitializeComponent(); } else { if (bookName.Length > 150) { MessageBox.Show("The name of the book can not be more than 150 characters", "Error", MessageBoxButton.OK); InitializeComponent(); } else if (authorName.Length > 100) { MessageBox.Show("The name of the author can not be more than 100 characters", "Error", MessageBoxButton.OK); InitializeComponent(); } else if (placeInLibrary.Length > 100) { MessageBox.Show("The place in the library can not be more than 100 characters", "Error", MessageBoxButton.OK); InitializeComponent(); } else if (givenTo.Length > 100) { MessageBox.Show("The name of the person that the books is given to can not be more than 100 characters", "Error", MessageBoxButton.OK); InitializeComponent(); } else { Table book = new Table() { AuthorName = authorName, BookName = bookName, PlaceInLibrary = placeInLibrary, GivenTo = givenTo, }; books.Tables.Add(book); books.SaveChanges(); } } } nameBox.Text = string.Empty; authorBox.Text = string.Empty; placeBox.Text = string.Empty; givenBox.Text = string.Empty; }