public List <Carro> ListAll() { CarroMotorDAO cm = new CarroMotorDAO(); CarroOpcionalDAO co = new CarroOpcionalDAO(); Database db = Database.GetInstance(); string qry = "SELECT * FROM carro"; DataSet ds = db.ExecuteQuery(qry); List <Carro> lc = new List <Carro>(); foreach (DataRow dr in ds.Tables[0].Rows) { Carro c = new Carro(); c.Id = int.Parse(dr["Id"].ToString()); c.Nome = dr["nome"].ToString(); c.Modelo = dr["modelo"].ToString(); c.PrecoBase = double.Parse(dr["precobase"].ToString()); c.Removido = int.Parse(dr["removido"].ToString()); c.Motor = cm.Read(c.Id); c.Opcional = co.Read(c.Id); lc.Add(c); } return(lc); }
public void Update(Carro c) { Database db = Database.GetInstance(); string qry = String.Format("UPDATE carro SET nome = '{0}', modelo = '{1}', precobase = '{2}' WHERE Id = '{3}'", c.Nome, c.Modelo, c.PrecoBase, c.Id); db.ExecuteNonQuery(qry); CarroOpcionalDAO co = new CarroOpcionalDAO(); CarroMotorDAO cm = new CarroMotorDAO(); Console.WriteLine("o id eh " + c.Id); co.Delete(c.Id); cm.Delete(c.Id); foreach (Opcional o in c.Opcional) { co.Create(c.Id, o.Id); } foreach (Motor m in c.Motor) { cm.Create(c.Id, m.Id); } }