public static Modele_Controller CheckExistsThenAdd(int IdModele) { GetExistingModeles(); if (ExistingModeles != null) { bool exists = ExistingModeles.Any(a => a.IdProperty == IdModele); if (exists) { return(ExistingModeles.Find(a => a.IdProperty == IdModele)); } else { Modele_Controller model = new Modele_Controller(IdModele); ExistingModeles.Add(model); AddToDb(model); return(model); } } else { Modele_Controller model = new Modele_Controller(IdModele); ExistingModeles.Add(model); AddToDb(model); return(model); } }
public static void AddToDb(Modele_Controller modele) { using (MySqlConnection c = BddSQL.InitConnexion()) { MySqlCommand command = c.CreateCommand(); command.CommandText = "INSERT INTO modeles (idmodele, label) VALUES (@idmodele, @label)"; command.Parameters.AddWithValue("@idmodele", modele.IdProperty); command.Parameters.AddWithValue("@label", modele.LabelProperty); command.ExecuteNonQuery(); } }