Пример #1
0
        public void AddBook(Book newBook)
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();
            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"INSERT INTO checkouts (patron_id, book_id, checkout_date, due_date, returned) VALUES (@PatronId, @BookId, @TodayDate, @DueDate, @Returned);";

            cmd.Parameters.Add(new MySqlParameter("@PatronId", _patronId));
            cmd.Parameters.Add(new MySqlParameter("@BookId", newBook.GetBookId()));
            cmd.Parameters.Add(new MySqlParameter("@TodayDate", DateTime.Now.Date.ToString("yyyy-MM-dd")));
            TimeSpan fourWeeks = new TimeSpan(28, 0, 0, 0);

            cmd.Parameters.Add(new MySqlParameter("@DueDate", DateTime.Now.Add(fourWeeks).Date.ToString("yyyy-MM-dd")));
            cmd.Parameters.Add(new MySqlParameter("@Returned", false));


            cmd.ExecuteNonQuery();
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
        }
Пример #2
0
 public override bool Equals(System.Object otherBook)
 {
     if (!(otherBook is Book))
     {
         return(false);
     }
     else
     {
         Book newBook        = (Book)otherBook;
         bool idEquality     = this.GetBookId().Equals(newBook.GetBookId());
         bool titleEquality  = this.GetTitle().Equals(newBook.GetTitle());
         bool copiesEquality = this.GetCopies().Equals(newBook.GetCopies());
         return(idEquality && titleEquality && copiesEquality);
     }
 }
Пример #3
0
        public void AddBook(Book newBook)
        {
            MySqlConnection conn = DB.Connection();

            conn.Open();
            var cmd = conn.CreateCommand() as MySqlCommand;

            cmd.CommandText = @"INSERT INTO authors_books (author_id, book_id) VALUES (@AuthorId, @BookId);";

            cmd.Parameters.Add(new MySqlParameter("@AuthorId", _authorId));
            cmd.Parameters.Add(new MySqlParameter("@BookId", newBook.GetBookId()));

            cmd.ExecuteNonQuery();
            conn.Close();
            if (conn != null)
            {
                conn.Dispose();
            }
        }