public void AddPirate(Pirate newPirate) { SqlConnection conn = DB.Connection(); conn.Open(); SqlCommand cmd = new SqlCommand("INSERT INTO pirates_ships (pirates_id, ships_id) VALUES (@PirateId, @ShipId);", conn); SqlParameter ShipIdParameter = new SqlParameter(); ShipIdParameter.ParameterName = "@ShipId"; ShipIdParameter.Value = this.GetId(); cmd.Parameters.Add(ShipIdParameter); SqlParameter PirateIdParameter = new SqlParameter(); PirateIdParameter.ParameterName = "@PirateId"; PirateIdParameter.Value = newPirate.GetId(); cmd.Parameters.Add(PirateIdParameter); cmd.ExecuteNonQuery(); if (conn != null) { conn.Close(); } }
public override bool Equals(System.Object otherPirate) { if (!(otherPirate is Pirate)) { return(false); } else { Pirate newPirate = (Pirate)otherPirate; bool idEquality = (this.GetId() == newPirate.GetId()); bool nameEquality = (this.GetName() == newPirate.GetName()); bool rank = (this.GetRank() == newPirate.GetRank()); return(idEquality && nameEquality); } }