예제 #1
0
        /// <summary>
        /// Selecciona todos los aircraft
        /// (miturriaga)
        /// </summary>
        /// <returns>La lista de aircraft</returns>
        public static List<Aircraft> Todos()
        {
            var aircrafts = new List<Aircraft>();

            try
            {
                string connString = ConfigurationManager.ConnectionStrings["PostgresConnection"].ConnectionString;

                var comando = new NpgsqlCommand() { CommandText = "Aircraft_All", CommandType = CommandType.StoredProcedure };

                using (var conn = new NpgsqlConnection(connString))
                {
                    conn.Open();
                    comando.Connection = conn;
                    NpgsqlDataReader ds = comando.ExecuteReader();

                    while (ds.Read())
                    {
                        var aircraft = new Aircraft();
                        aircraft.SetDesde(ds);
                        aircrafts.Add(aircraft);
                    }
                    conn.Close();
                }
            }
            catch (Exception ex) { }

            return aircrafts;
        }
예제 #2
0
        /// <summary>
        /// Selecciona los aircraft dada la pagina y cantidad de resultados por pagina
        /// (miturriaga)
        /// </summary>
        /// <param name="cantidadResultados">Cantidad de resultado por pagina</param>
        /// <param name="pagina">Pagina que se necesita ver</param>
        /// <returns>La lista de aircraft</returns>
        public List<Aircraft> Todos(int cantidadResultados, int pagina)
        {
            var aircrafts = new List<Aircraft>();
            int index = cantidadResultados * (pagina - 1);

            try
            {
                string connString = ConfigurationManager.ConnectionStrings["PostgresConnection"].ConnectionString;

                var comando = new NpgsqlCommand() { CommandText = "Aircraft_Todos", CommandType = CommandType.StoredProcedure };
                comando.Parameters.Add(new NpgsqlParameter("inIndex", NpgsqlDbType.Integer));
                comando.Parameters[0].Value = index;
                comando.Parameters.Add(new NpgsqlParameter("inNext", NpgsqlDbType.Integer));
                comando.Parameters[1].Value = cantidadResultados;

                using (var conn = new NpgsqlConnection(connString))
                {
                    conn.Open();
                    comando.Connection = conn;
                    NpgsqlDataReader ds = comando.ExecuteReader();

                    while (ds.Read())
                    {
                        var aircraft = new Aircraft();
                        aircraft.SetDesde(ds);
                        aircrafts.Add(aircraft);
                    }
                    conn.Close();
                }
            }
            catch (Exception ex) { }

            return aircrafts;
        }