static void AddAuthor(Authors aut) { using (PublishingHouseEntities db = new PublishingHouseEntities()) { db.Authors.Add(aut); db.SaveChanges(); Console.WriteLine("New author with name " + aut.FirstName + " " + aut.LastName + " added"); } }
static Authors GetAuthorsByName(string name) { using (PublishingHouseEntities db = new PublishingHouseEntities()) { var author = (from a in db.Authors where a.FirstName == name select a).FirstOrDefault(); // if not, return null return(author); } }
static void ShowAuthors() { using (PublishingHouseEntities db = new PublishingHouseEntities()) { var books = db.Books.ToList(); foreach (var item in books) { Console.WriteLine($"{item.NameBook} {item.Authors.FirstName}"); } } }
static void AddBook(Books _book) { using (PublishingHouseEntities db = new PublishingHouseEntities()) { Books currbook = db.Books.Where(b => b.NameBook == _book.NameBook).FirstOrDefault(); if (currbook == null) { db.Books.Add(_book); db.SaveChanges(); Console.WriteLine("Книга добавлена"); } } }
static void AddTheme(Themes theme) { using (PublishingHouseEntities db = new PublishingHouseEntities()) { Themes t = db.Themes.Where(h => h.NameTheme == theme.NameTheme).FirstOrDefault(); if (t == null) { db.Themes.Add(theme); db.SaveChanges(); Console.WriteLine("Тема добавлена"); } } }