/// <summary> /// Checking genre's input and sending it to the database /// </summary> /// <returns>True if genre sent to DB, otherwise false</returns> private bool AddItemGenre() { GenreAddViewModel viewmodel = (GenreAddViewModel)DataContext; Genre genre = viewmodel.MyGenre; if (string.IsNullOrEmpty(genre.Name)) { MessageBox.Show("Name cannnot be empty."); return(false); } foreach (var g in Genres.GenresList) { if (g.Name == genre.Name) { MessageBox.Show("Genre already exists!"); return(false); } } try { int id = MSAConnectionDB.SaveGenreToDB(genre); genre.GenreId = id; Genres.AddGenre(genre); ActivateMainWindow(); } catch (Exception e) { MessageBox.Show(e.Message); } return(true); }
/// <summary> /// Save button - sending data to be save to DB /// </summary> /// <param name="sender">The source of the event</param> /// <param name="e">The instance containing the event data</param> private void Save_Button_Click(object sender, RoutedEventArgs e) { if (MSAConnectionDB.SaveDataToDB()) { MessageBox.Show("Changes saved"); } else { MessageBox.Show("No changes"); } }
public MainWindow() { InitializeComponent(); try { MSAConnectionDB.LoadData(); DataContext = new { collection = new BooksListViewModel(), detail = new BookDetailViewModel() }; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// Checking author's input and sending it to the database /// </summary> /// <returns>True if author sent to DB, otherwise false</returns> private bool AddItemAuthor() { AuthorAddViewModel viewmodel = (AuthorAddViewModel)DataContext; Author author = viewmodel.MyAuthor; if (string.IsNullOrEmpty(author.LastName)) { MessageBox.Show("Last name cannnot be empty."); return(false); } try { int id = MSAConnectionDB.SaveAuthorToDB(author); author.AuthorId = id; Authors.AddAuthor(author); ActivateMainWindow(); } catch (Exception e) { MessageBox.Show(e.Message); } return(true); }
/// <summary> /// Checking books's input and sending it to the database /// </summary> /// <returns>True if book sent to DB, otherwise false</returns> private bool AddItemBook() { BookAddViewModel viewmodel = (BookAddViewModel)DataContext; Book book = viewmodel.MyBook; if (string.IsNullOrEmpty(book.Title)) { MessageBox.Show("Title cannnot be empty."); return(false); } if (book.Author_AtBook == null) { MessageBox.Show("Author must be added."); return(false); } if (book.Genre_AtBook == null) { MessageBox.Show("Genre must be added."); return(false); } try { int id = MSAConnectionDB.SaveBookToDB(book); book.BookId = id; Books.AddBook(book); Genres.AddBookToGenre(book, book.Genre_AtBook); Authors.AddBookToAuthor(book, book.Author_AtBook); ActivateMainWindow(); } catch (Exception e) { MessageBox.Show(e.Message); } return(true); }