Example #1
0
 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);
         }
     }
 }
Example #2
0
 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);
     }
 }
Example #3
0
 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);
         }
     }
 }