static void GuardarConPlato() { // Crear Restaurante con dos platos Restaurante r = new Restaurante(); Console.WriteLine("Ingrese el rut del Restaurante: "); r.Rut = Console.ReadLine(); Console.WriteLine("Ingrese la Razon Social del Restaurante: "); r.RazonSocial = Console.ReadLine(); Console.WriteLine("Ingrese la Calificacion inicial del Restaurante: "); r.SumaCalificacion = int.Parse(Console.ReadLine()); r.CantidadCalificacion = 1; Plato p = new Plato(); Console.WriteLine("Ingrese el nombre de un plato: "); p.Nombre = Console.ReadLine(); Console.WriteLine(" Ingrese la descripcion de un plato: "); p.Descripcion = Console.ReadLine(); Console.WriteLine("Ingrese el precio del plato: "); p.Precio = decimal.Parse(Console.ReadLine()); r.agregarPlato(p); Plato p2 = new Plato(); Console.WriteLine("Ingrese el nombre de un plato:"); p2.Nombre = Console.ReadLine(); Console.WriteLine("Ingrese la descripcion de un plato: "); p2.Descripcion = Console.ReadLine(); Console.WriteLine(" Ingrese el precio del plato: "); p2.Precio = decimal.Parse(Console.ReadLine()); r.agregarPlato(p2); r.GuardarConPlato(); //guardar el restaurante y su menu //consultar un restaurante y su menu r.LeerConPlato(); Console.WriteLine(r.RazonSocial); Console.WriteLine("Menu: "); foreach (Plato a in r.Menu) { Console.WriteLine(a.Nombre + " - $ " + a.Precio.ToString()); } Console.ReadLine(); }
public Restaurante LeerConPlato() { SqlCommand cmd = new SqlCommand(); cmd.CommandType = CommandType.StoredProcedure; //indico que voy a ejecutar un procedimiento almacenado en la bd cmd.CommandText = "Restaurantes_SelectByID"; //indico el procedimiento string sConnectionString = @"Server=(localdb)\ProjectsV13;DataBase=Fameliques;Integrated Security=true;"; SqlConnection conn = new SqlConnection(sConnectionString); Restaurante retorno = null; SqlDataReader drResults; cmd.Connection = conn; cmd.Parameters.Add(new SqlParameter("@RestauranteId", this.RestauranteId)); conn.Open(); // login failed error. me pide el id al agregar, se deberia hacer por atras. drResults = cmd.ExecuteReader(CommandBehavior.CloseConnection); if (drResults.Read()) { retorno = this; this.Rut = drResults["Rut"].ToString(); this.RazonSocial = drResults["RazonSocial"].ToString(); drResults.NextResult(); while (drResults.Read()) { Plato p = new Plato(); p.Descripcion = drResults["Descripcion"].ToString(); p.Nombre = drResults["Nombre"].ToString(); p.PlatoId = int.Parse(drResults["PlatoId"].ToString()); p.Precio = decimal.Parse(drResults["Precio"].ToString()); p.ElRestaurante = this; this.Menu.Add(p); } } drResults.Close(); conn.Close(); return(retorno); }
public void agregarPlato(Plato p) { Menu.Add(p); // definir este metodo creo. }