コード例 #1
0
 public override bool Equals(System.Object otherAuthor)
 {
     if (!(otherAuthor is Author))
     {
         return(false);
     }
     else
     {
         Author newAuthor    = (Author)otherAuthor;
         bool   idEquality   = this.GetAuthorId().Equals(newAuthor.GetAuthorId());
         bool   nameEquality = this.GetAuthorName().Equals(newAuthor.GetAuthorName());
         return(idEquality && nameEquality);
     }
 }
コード例 #2
0
        public void AddAuthor(Author newAuthor)
        {
            MySqlConnection conn = DB.Connection();

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

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

            cmd.Parameters.Add(new MySqlParameter("@BookId", _bookId));
            cmd.Parameters.Add(new MySqlParameter("@AuthorId", newAuthor.GetAuthorId()));

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