public void ListAllAuthors() { using (BooksDB context = new BooksDB()) { List <Author> authors = BLL.ReturnAuthors(); foreach (var author in authors) { Console.WriteLine(author.AuthorID + " " + author.FirstName + " " + author.LastName + " age: " + author.Age); } } }
internal static List <Author> ReturnAuthors() { using (BooksDB ctx = new BooksDB()) { List <Author> authors = new List <Author>(); foreach (var author in ctx.Authors) { authors.Add(author); } return(authors); } }
internal static bool AddAuthor(Author author) { using (_context = new BooksDB()) { try { _context.Authors.Add(author); _context.Database.Log = Console.WriteLine; _context.SaveChanges(); return(true); } catch (Exception) { return(false); } } }