public void AddNew(string bookName, string authorName, string bookDescription, DateTime bookDate) { using (dBEntities = new BookTrackerDBEntities()) { if (!(dBEntities.Books.Any(x => x.Name.Equals(bookName)))) { int authorId; if (!(dBEntities.Authors.Any(x => x.FullName.Equals(authorName)))) { Author author = new Author { FullName = authorName }; dBEntities.Authors.Add(author); dBEntities.SaveChanges(); authorId = author.Id; } Author tempAuthor = dBEntities.Authors.First(x => x.FullName.Equals(authorName)); authorId = tempAuthor.Id; Book book = new Book { Name = bookName, AuthorID = authorId, Description = bookDescription, PublishingDate = bookDate }; dBEntities.Books.Add(book); dBEntities.SaveChanges(); MessageBox.Show("Book succesfully added!"); return; } MessageBox.Show("Seems like this book already exists. I am not gonna add it!"); return; } }
public ShellViewModel() { db = new BookTrackerDBEntities(); }
public ReadBooksViewModel() { db = new BookTrackerDBEntities(); _books = new BindableCollection <Book>(); }