Exemplo n.º 1
0
    public static List<Book> GetBooks(Boolean useDB)
    {
      try
      {
        DataTable dt;
        List<Book> temp = new List<Book>();
        // Haetaan kirjoja, db-kerroksen palauttama DataTable mapataan olioiksi. ORM Object Relational Mapping
        if (useDB)
        {
          dt = DBBooks.GetBooks(cs);
        }
        else
        {
          dt = DBBooks.GetTestData();
        }

        // Tehdään ORM eli DataTablen rivi muutetaan olioiksi
        Book book;
        foreach (DataRow dr in dt.Rows)
        {
          book = new Book((int)dr[0]);
          book.Author = dr["author"].ToString();
          book.Name = dr["name"].ToString();
          book.Country = dr["country"].ToString();
          book.Year = (int)dr["year"];

          // Olio lisätään kokoelmaan
          temp.Add(book);
        }

        return temp;
      }
      catch (Exception)
      {

        throw;
      }

    }
Exemplo n.º 2
0
 public static void UpdateBook(Book book)
 {
   try
   {
     int lkm = DBBooks.UpdateBook(cs, book.Id, book.Name, book.Author, book.Country, book.Year);
   }
   catch (Exception ex)
   {
     throw ex;
   }
 }