public static Achat Create(Achat achat) { using (SqlConnection connection = DataBase.GetConnection()) { connection.Open(); SqlCommand command = new SqlCommand(CREATE, connection); command.Parameters.AddWithValue("@mail", achat.Mail); command.Parameters.AddWithValue("@id_musique", achat.Id_musique); command.Parameters.AddWithValue("@statut", achat.Statut); command.ExecuteScalar(); } return(achat); }
public static bool Update(Achat achat) { bool aEteModifiee = false; using (SqlConnection connection = DataBase.GetConnection()) { connection.Open(); SqlCommand command = new SqlCommand(UPDATE, connection); command.Parameters.AddWithValue("@mail", achat.Mail); command.Parameters.AddWithValue("@id_musique", achat.Id_musique); command.Parameters.AddWithValue("@statut", achat.Statut); aEteModifiee = command.ExecuteNonQuery() != 0; } return(aEteModifiee); }
public static Achat Get(int id_musique, string mail) { Achat achat = null; using (SqlConnection connection = DataBase.GetConnection()) { connection.Open(); SqlCommand command = new SqlCommand(GET, connection); command.Parameters.AddWithValue("@id_musique", id_musique); command.Parameters.AddWithValue("@mail", mail); SqlDataReader reader = command.ExecuteReader(); if (reader.Read()) { achat = new Achat(reader.GetString(0), reader.GetInt32(1), reader.GetInt32(2)); } } return(achat); }