// 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 <CrudeBookingContactMethodContract> FetchWithFilter(System.Guid bookingContactMethodId, System.Guid bookingId, string contactMethodRcd, string contactMethodWay, string comment, System.Guid userId, System.DateTime dateTime)
        {
            var list = new List <CrudeBookingContactMethodContract>();
            List <CrudeBookingContactMethodData> dataList = CrudeBookingContactMethodData.FetchWithFilter(
                bookingContactMethodId: bookingContactMethodId,
                bookingId: bookingId,
                contactMethodRcd: contactMethodRcd,
                contactMethodWay: contactMethodWay,
                comment: comment,
                userId: userId,
                dateTime: dateTime
                );

            foreach (CrudeBookingContactMethodData data in dataList)
            {
                var crudeBookingContactMethodContract = new CrudeBookingContactMethodContract();
                DataToContract(data, crudeBookingContactMethodContract);
                list.Add(crudeBookingContactMethodContract);
            }

            return(list);
        }
 // copy all columns from a SOAP Contract to a serialized data object
 // links:
 //  docLink: http://sql2x.org/documentationLink/10700d38-2227-4021-be12-2f4f206f5dd9
 public static void ContractToData(CrudeBookingContactMethodContract contract, CrudeBookingContactMethodData data)
 {
     data.BookingContactMethodId = contract.BookingContactMethodId;
     data.BookingId        = contract.BookingId;
     data.ContactMethodRcd = contract.ContactMethodRcd;
     data.ContactMethodWay = contract.ContactMethodWay;
     data.Comment          = contract.Comment;
     data.UserId           = contract.UserId;
     data.DateTime         = contract.DateTime;
 }
 // delete a row in table based on primary key
 // links:
 //  docLink: http://sql2x.org/documentationLink/eb0597e0-8ea0-425c-88af-213a170bbd5e
 public void Delete(System.Guid bookingContactMethodId)
 {
     CrudeBookingContactMethodData.Delete(bookingContactMethodId);
 }
 // get a count of rows in table
 // links:
 //  docLink: http://sql2x.org/documentationLink/7cd5e52c-b3d7-4566-a27a-408d0732dd88
 public int FetchAllCount()
 {
     return(CrudeBookingContactMethodData.FetchAllCount());
 }
 // fetch by Foreign key into new List of class instances
 // links:
 //  docLink: http://sql2x.org/documentationLink/a7599485-4f00-4ebf-974d-53f69c43654e
 public List <CrudeBookingContactMethodContract> FetchByContactMethodRcd(string contactMethodRcd)
 {
     return(DataListToContractList(CrudeBookingContactMethodData.FetchByContactMethodRcd(contactMethodRcd)));
 }
 // fetch by Foreign key into new List of class instances
 // links:
 //  docLink: http://sql2x.org/documentationLink/a7599485-4f00-4ebf-974d-53f69c43654e
 public List <CrudeBookingContactMethodContract> FetchByUserId(System.Guid userId)
 {
     return(DataListToContractList(CrudeBookingContactMethodData.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 <CrudeBookingContactMethodData> FetchWithFilter(System.Guid bookingContactMethodId, System.Guid bookingId, string contactMethodRcd, string contactMethodWay, string comment, System.Guid userId, System.DateTime dateTime)
        {
            var dataList = new List <CrudeBookingContactMethodData>();

            // create query against booking_contact_method
            // 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 booking_contact_method_id, booking_id, contact_method_rcd, contact_method_way, comment, user_id, date_time
                            from [booking_contact_method]
                            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 (bookingContactMethodId != Guid.Empty)
                    {
                        sql += "  and booking_contact_method_id = @booking_contact_method_id";
                        command.Parameters.Add("@booking_contact_method_id", SqlDbType.UniqueIdentifier).Value = bookingContactMethodId;
                    }
                    if (bookingId != Guid.Empty)
                    {
                        sql += "  and booking_id = @booking_id";
                        command.Parameters.Add("@booking_id", SqlDbType.UniqueIdentifier).Value = bookingId;
                    }
                    if (!string.IsNullOrEmpty(contactMethodRcd))
                    {
                        sql += "  and contact_method_rcd like '%' + @contact_method_rcd + '%'";
                        command.Parameters.Add("@contact_method_rcd", SqlDbType.NVarChar).Value = contactMethodRcd.Replace("'", "''");
                    }
                    if (!string.IsNullOrEmpty(contactMethodWay))
                    {
                        sql += "  and contact_method_way like '%' + @contact_method_way + '%'";
                        command.Parameters.Add("@contact_method_way", SqlDbType.NVarChar).Value = contactMethodWay.Replace("'", "''");
                    }
                    if (!string.IsNullOrEmpty(comment))
                    {
                        sql += "  and comment like '%' + @comment + '%'";
                        command.Parameters.Add("@comment", SqlDbType.NVarChar).Value = comment.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;
                    }
                    command.CommandText = sql;

                    // execute query against booking_contact_method
                    // 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 booking_contact_method
                    // 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 CrudeBookingContactMethodData();
                        data.Populate(reader);
                        dataList.Add(data);
                    }
                }

                return(dataList);
            }
        }
Esempio n. 8
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:
 //  ContactMethodRcd: key of table CrudeBookingContactMethodData
 public List <CrudeBookingContactMethodModel> FetchByContactMethodRcd(string contactMethodRcd)
 {
     return(DataListToModelList(CrudeBookingContactMethodData.FetchByContactMethodRcd(contactMethodRcd)));
 }
Esempio n. 9
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:
 //  BookingId: key of table CrudeBookingContactMethodData
 public List <CrudeBookingContactMethodModel> FetchByBookingId(System.Guid bookingId)
 {
     return(DataListToModelList(CrudeBookingContactMethodData.FetchByBookingId(bookingId)));
 }