Exemplo n.º 1
0
 public static List <Book> GetBooks(bool useDB)
 {
     try
     {
         DataTable   table;
         List <Book> books = new List <Book>();
         if (useDB)
         {
             table = DBLibrary.GetBooks(cs);
         }
         else
         {
             table = DBLibrary.GetTestData();
         }
         Book book;
         foreach (DataRow row in table.Rows)
         {
             book         = new Book((int)row[0]);
             book.Name    = row["name"].ToString();
             book.Author  = row["author"].ToString();
             book.Country = row["country"].ToString();
             book.Year    = (int)row["year"];
             books.Add(book);
         }
         return(books);
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 2
0
 public static int UpdateBook(Book book)
 {
     try
     {
         int count = DBLibrary.UpdateBook(cs, book.ID, book.Name, book.Author, book.Country, book.Year);
         return(count);
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 3
0
 public static bool DeleteBook(Book book)
 {
     try
     {
         int count = DBLibrary.DeleteBook(cs, book.ID);
         if (count > 0)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 4
0
 public static bool InsertBook(Book book)
 {
     try
     {
         int count = DBLibrary.InsertBook(cs, book.Name, book.Author, book.Country, book.Year);
         if (count > 0)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }