// fetch all from table into new List of class instances, with a limit on number of returned rows and order by columns
        // links:
        //  docLink: http://sql2x.org/documentationLink/dfaa482b-059b-4f17-a9a9-4885138dbb46
        public static List <CrudeAirportIdentifierData> FetchAllWithLimit(int limit)
        {
            var dataList = new List <CrudeAirportIdentifierData>();

            // create query against airport_identifier
            // this will be ansi sql and parameterized
            // parameterized queries are a good way of preventing sql injection
            //   and to make sure the query plan is pre-compiled
            // links:
            // docLink: http://sql2x.org/documentationLink/41f82773-6d37-4ebe-840c-c60e06337f45
            string sql = @" select top " + limit.ToString() + @" airport_identifier_id, airport_id, airport_identifier_type_rcd, airport_identifier_code, user_id, date_time
                            from [airport_identifier]
                            order by airport_identifier_code";

            // open standard connection
            // the connection is found in web.config
            // the connection is closed upon completion of the reader
            // links:
            // docLink: http://sql2x.org/documentationLink/da228d98-b30e-4d79-89ae-98e813437753
            using (var conn = new SqlConnection(Conn.ConnectionString)) {
                conn.Open();

                using (var command = new SqlCommand(sql, conn)) {
                    // execute query against airport_identifier
                    // if the query fails in the preprocessor of sql server
                    //   an exception will be raised
                    // links:
                    // docLink: http://sql2x.org/documentationLink/c32ad724-8a03-4b4c-b6fb-a5abfb1d707e
                    IDataReader reader = command.ExecuteReader(CommandBehavior.SingleResult);

                    // read all rows returned from the query of airport_identifier
                    // read all columns from the datareader and
                    //   populate the List of C# objects with them
                    // links:
                    // docLink: http://sql2x.org/documentationLink/9ba4395d-d8a4-4427-b80f-7b828e34da7a
                    while (reader.Read())
                    {
                        var data = new CrudeAirportIdentifierData();
                        data.Populate(reader);
                        dataList.Add(data);
                    }
                }

                return(dataList);
            }
        }
        // fetch all rows from table airport_identifier into new List of class instances
        // links:
        //  docLink: http://sql2x.org/documentationLink/7ca0c014-527e-4a0a-bd1f-12f4d8ea4b43
        public static List <CrudeAirportIdentifierData> FetchAll()
        {
            var dataList = new List <CrudeAirportIdentifierData>();

            // create query against airport_identifier
            // this will be ansi sql and parameterized
            // parameterized queries are a good way of preventing sql injection
            //   and to make sure the query plan is pre-compiled
            // links:
            // docLink: http://sql2x.org/documentationLink/72f9f1bc-447c-4327-9d26-4b0790a07ff8
            string sql = @" select airport_identifier_id, airport_id, airport_identifier_type_rcd, airport_identifier_code, user_id, date_time
                            from [airport_identifier]
                            order by airport_identifier_code";

            // open standard connection
            // the connection is found in web.config
            // the connection is closed upon completion of the reader
            // links:
            // docLink: http://sql2x.org/documentationLink/952b3f82-bc00-4e82-9430-6bc26ff8bc4d
            using (var conn = new SqlConnection(Conn.ConnectionString)) {
                conn.Open();

                using (var command = new SqlCommand(sql, conn)) {
                    // execute query against airport_identifier
                    // if the query fails in the preprocessor of sql server
                    //   an exception will be raised
                    // links:
                    // docLink: http://sql2x.org/documentationLink/ed55cc5b-d6be-4f5e-9385-ee726dfc2bf1
                    IDataReader reader = command.ExecuteReader(CommandBehavior.SingleResult);

                    // read all rows returned from the query of airport_identifier
                    // read all columns from the datareader and
                    //   populate the List of C# objects with them
                    // links:
                    // docLink: http://sql2x.org/documentationLink/c1b8b800-b250-4822-a699-d93a35f4414d
                    while (reader.Read())
                    {
                        var data = new CrudeAirportIdentifierData();
                        data.Populate(reader);
                        dataList.Add(data);
                    }
                }

                return(dataList);
            }
        }
        // fetch all rows from table into new List of Contracts, filtered by any column
        // links:
        //  docLink: http://sql2x.org/documentationLink/ce01ef4a-5cd0-4e51-b211-9c0a15b791a0
        public List <CrudeAirportIdentifierContract> FetchWithFilter(System.Guid airportIdentifierId, System.Guid airportId, string airportIdentifierTypeRcd, string airportIdentifierCode, System.Guid userId, System.DateTime dateTime)
        {
            var list = new List <CrudeAirportIdentifierContract>();
            List <CrudeAirportIdentifierData> dataList = CrudeAirportIdentifierData.FetchWithFilter(
                airportIdentifierId: airportIdentifierId,
                airportId: airportId,
                airportIdentifierTypeRcd: airportIdentifierTypeRcd,
                airportIdentifierCode: airportIdentifierCode,
                userId: userId,
                dateTime: dateTime
                );

            foreach (CrudeAirportIdentifierData data in dataList)
            {
                var crudeAirportIdentifierContract = new CrudeAirportIdentifierContract();
                DataToContract(data, crudeAirportIdentifierContract);
                list.Add(crudeAirportIdentifierContract);
            }

            return(list);
        }
Example #4
0
 // fetch by Search key into current object
 // links:
 //  crud definition: https://en.wikipedia.org/wiki/Create,_read,_update_and_delete
 //  docLink: http://sql2x.org/documentationLink/87368fa6-b618-4f0c-acbb-1fc4e273bb2d
 // parameters:
 //  UserId: key of table CrudeAirportIdentifierData
 public List <CrudeAirportIdentifierModel> FetchByUserId(System.Guid userId)
 {
     return(DataListToModelList(CrudeAirportIdentifierData.FetchByUserId(userId)));
 }
Example #5
0
 // fetch by Search key into current object
 // links:
 //  crud definition: https://en.wikipedia.org/wiki/Create,_read,_update_and_delete
 //  docLink: http://sql2x.org/documentationLink/87368fa6-b618-4f0c-acbb-1fc4e273bb2d
 // parameters:
 //  AirportIdentifierTypeRcd: key of table CrudeAirportIdentifierData
 public List <CrudeAirportIdentifierModel> FetchByAirportIdentifierTypeRcd(string airportIdentifierTypeRcd)
 {
     return(DataListToModelList(CrudeAirportIdentifierData.FetchByAirportIdentifierTypeRcd(airportIdentifierTypeRcd)));
 }
Example #6
0
 // delete row
 // links:
 //  docLink: http://sql2x.org/documentationLink/59823bf7-4ad8-4684-a48b-2abd49c607ee
 public void Delete(System.Guid airportIdentifierId)
 {
     CrudeAirportIdentifierData.Delete(airportIdentifierId);
 }
Example #7
0
 // get a count of rows in table
 // links:
 //  docLink: http://sql2x.org/documentationLink/39677f9e-daee-45c6-9527-da98a0d7958d
 public int FetchAllCount()
 {
     return(CrudeAirportIdentifierData.FetchAllCount());
 }
 // fetch by Foreign key into new List of class instances
 // links:
 //  docLink: http://sql2x.org/documentationLink/a7599485-4f00-4ebf-974d-53f69c43654e
 public List <CrudeAirportIdentifierContract> FetchByAirportIdentifierTypeRcd(string airportIdentifierTypeRcd)
 {
     return(DataListToContractList(CrudeAirportIdentifierData.FetchByAirportIdentifierTypeRcd(airportIdentifierTypeRcd)));
 }
 // fetch by Foreign key into new List of class instances
 // links:
 //  docLink: http://sql2x.org/documentationLink/a7599485-4f00-4ebf-974d-53f69c43654e
 public List <CrudeAirportIdentifierContract> FetchByUserId(System.Guid userId)
 {
     return(DataListToContractList(CrudeAirportIdentifierData.FetchByUserId(userId)));
 }
        // fetch all from table into new List of class instances, filtered by any column
        // links:
        //  docLink: http://sql2x.org/documentationLink/a736bbfd-030d-492e-a86a-7a5e478eeb79
        public static List <CrudeAirportIdentifierData> FetchWithFilter(System.Guid airportIdentifierId, System.Guid airportId, string airportIdentifierTypeRcd, string airportIdentifierCode, System.Guid userId, System.DateTime dateTime)
        {
            var dataList = new List <CrudeAirportIdentifierData>();

            // create query against airport_identifier
            // this will be ansi sql and parameterized
            // parameterized queries are a good way of preventing sql injection
            //   and to make sure the query plan is pre-compiled
            // links:
            // docLink: http://sql2x.org/documentationLink/06da7a50-8760-48cd-b789-a41cac3edd13
            string sql = @" select airport_identifier_id, airport_id, airport_identifier_type_rcd, airport_identifier_code, user_id, date_time
                            from [airport_identifier]
                            where 1 = 1";

            // open standard connection
            // the connection is found in web.config
            // the connection is closed upon completion of the reader
// links:
// docLink: http://sql2x.org/documentationLink/6ec2495f-3a49-4a94-ad59-0ce064fc8654
            using (var conn = new SqlConnection(Conn.ConnectionString)) {
                conn.Open();

                using (var command = new SqlCommand(sql, conn)) {
                    // add search column(s) if they are not null or empty
                    // this search column(s) will be used together with the prepared ansi sql statement
                    // links:
                    // docLink: http://sql2x.org/documentationLink/2193123a-3534-412b-8521-dac14bb3884d
                    if (airportIdentifierId != Guid.Empty)
                    {
                        sql += "  and airport_identifier_id = @airport_identifier_id";
                        command.Parameters.Add("@airport_identifier_id", SqlDbType.UniqueIdentifier).Value = airportIdentifierId;
                    }
                    if (airportId != Guid.Empty)
                    {
                        sql += "  and airport_id = @airport_id";
                        command.Parameters.Add("@airport_id", SqlDbType.UniqueIdentifier).Value = airportId;
                    }
                    if (!string.IsNullOrEmpty(airportIdentifierTypeRcd))
                    {
                        sql += "  and airport_identifier_type_rcd like '%' + @airport_identifier_type_rcd + '%'";
                        command.Parameters.Add("@airport_identifier_type_rcd", SqlDbType.NVarChar).Value = airportIdentifierTypeRcd.Replace("'", "''");
                    }
                    if (!string.IsNullOrEmpty(airportIdentifierCode))
                    {
                        sql += "  and airport_identifier_code like '%' + @airport_identifier_code + '%'";
                        command.Parameters.Add("@airport_identifier_code", SqlDbType.NVarChar).Value = airportIdentifierCode.Replace("'", "''");
                    }
                    if (userId != Guid.Empty)
                    {
                        sql += "  and user_id = @user_id";
                        command.Parameters.Add("@user_id", SqlDbType.UniqueIdentifier).Value = userId;
                    }
                    if (dateTime != DateTime.MinValue)
                    {
                        sql += "  and date_time = @date_time";
                        command.Parameters.Add("@date_time", SqlDbType.DateTime).Value = dateTime;
                    }
                    sql += " order by airport_identifier_code";

                    command.CommandText = sql;

                    // execute query against airport_identifier
                    // if the query fails in the preprocessor of sql server
                    //   an exception will be raised
                    // links:
                    // docLink: http://sql2x.org/documentationLink/9f9fcbf4-4764-4b2e-8dc6-41d0366c95c9
                    IDataReader reader = command.ExecuteReader(CommandBehavior.SingleResult);

                    // read all rows returned from the query of airport_identifier
                    // read all columns from the datareader and
                    //   populate the List of C# objects with them
                    // links:
                    // docLink: http://sql2x.org/documentationLink/60181c7c-4a5e-41a3-9599-4e7a0aaf0cc8
                    while (reader.Read())
                    {
                        var data = new CrudeAirportIdentifierData();
                        data.Populate(reader);
                        dataList.Add(data);
                    }
                }

                return(dataList);
            }
        }