public int?createPot(Pots pot) { Potters potter = this.getPotterById(pot.PottersId); if (potter == null) { return(null); } return((new PotsContext(connectionString)).createPot(pot)); }
public int?createPot(Pots pot) { using (MySqlConnection conn = getConnection()) { conn.Open(); MySqlCommand command = new MySqlCommand("insert into pots (PottersId, Name, Description) values (?pottersid, ?name, ?description)", conn); command.Parameters.AddWithValue("?pottersid", pot.PottersId); command.Parameters.AddWithValue("?name", pot.PotterName); command.Parameters.AddWithValue("?description", pot.Description); int rowsaffected = command.ExecuteNonQuery(); if (rowsaffected == 1) { return((int)command.LastInsertedId); } } return(null); }