/// <summary>
        /// Reads data from the provided data reader and returns
        /// an array of mapped objects.
        /// </summary>
        /// <param name="reader">The <see cref="System.Data.IDataReader"/> object to read data from the table.</param>
        /// <param name="startIndex">The index of the first record to map.</param>
        /// <param name="length">The number of records to map.</param>
        /// <param name="totalRecordCount">A reference parameter that returns the total number
        /// of records in the reader object if 0 was passed into the method; otherwise it returns -1.</param>
        /// <returns>An array of <see cref="ResidentialVoIPRow"/> objects.</returns>
        protected virtual ResidentialVoIPRow[] MapRecords(IDataReader reader,
                                                          int startIndex, int length, ref int totalRecordCount)
        {
            if (0 > startIndex)
            {
                throw new ArgumentOutOfRangeException("startIndex", startIndex, "StartIndex cannot be less than zero.");
            }
            if (0 > length)
            {
                throw new ArgumentOutOfRangeException("length", length, "Length cannot be less than zero.");
            }

            int user_idColumnIndex             = reader.GetOrdinal("user_id");
            int statusColumnIndex              = reader.GetOrdinal("status");
            int date_first_usedColumnIndex     = reader.GetOrdinal("date_first_used");
            int date_last_usedColumnIndex      = reader.GetOrdinal("date_last_used");
            int passwordColumnIndex            = reader.GetOrdinal("password");
            int allow_inbound_callsColumnIndex = reader.GetOrdinal("allow_inbound_calls");
            int service_idColumnIndex          = reader.GetOrdinal("service_id");
            int retail_acct_idColumnIndex      = reader.GetOrdinal("retail_acct_id");

            System.Collections.ArrayList recordList = new System.Collections.ArrayList();
            int ri = -startIndex;

            while (reader.Read())
            {
                ri++;
                if (ri > 0 && ri <= length)
                {
                    ResidentialVoIPRow record = new ResidentialVoIPRow();
                    recordList.Add(record);

                    record.User_id = Convert.ToString(reader.GetValue(user_idColumnIndex));
                    record.Status  = Convert.ToByte(reader.GetValue(statusColumnIndex));
                    if (!reader.IsDBNull(date_first_usedColumnIndex))
                    {
                        record.Date_first_used = Convert.ToDateTime(reader.GetValue(date_first_usedColumnIndex));
                    }
                    if (!reader.IsDBNull(date_last_usedColumnIndex))
                    {
                        record.Date_last_used = Convert.ToDateTime(reader.GetValue(date_last_usedColumnIndex));
                    }
                    record.Password            = Convert.ToString(reader.GetValue(passwordColumnIndex));
                    record.Allow_inbound_calls = Convert.ToByte(reader.GetValue(allow_inbound_callsColumnIndex));
                    if (!reader.IsDBNull(service_idColumnIndex))
                    {
                        record.Service_id = Convert.ToInt16(reader.GetValue(service_idColumnIndex));
                    }
                    record.Retail_acct_id = Convert.ToInt32(reader.GetValue(retail_acct_idColumnIndex));

                    if (ri == length && 0 != totalRecordCount)
                    {
                        break;
                    }
                }
            }

            totalRecordCount = 0 == totalRecordCount ? ri + startIndex : -1;
            return((ResidentialVoIPRow[])(recordList.ToArray(typeof(ResidentialVoIPRow))));
        }
        /// <summary>
        /// Adds a new record into the <c>ResidentialVoIP</c> table.
        /// </summary>
        /// <param name="value">The <see cref="ResidentialVoIPRow"/> object to be inserted.</param>
        public virtual void Insert(ResidentialVoIPRow value)
        {
            string sqlStr = "INSERT INTO [dbo].[ResidentialVoIP] (" +
                            "[user_id], " +
                            "[status], " +
                            "[password], " +
                            "[allow_inbound_calls], " +
                            "[service_id], " +
                            "[retail_acct_id]" +
                            ") VALUES (" +
                            _db.CreateSqlParameterName("User_id") + ", " +
                            _db.CreateSqlParameterName("Status") + ", " +
                            _db.CreateSqlParameterName("Password") + ", " +
                            _db.CreateSqlParameterName("Allow_inbound_calls") + ", " +
                            _db.CreateSqlParameterName("Service_id") + ", " +
                            _db.CreateSqlParameterName("Retail_acct_id") + ")";
            IDbCommand cmd = _db.CreateCommand(sqlStr);

            AddParameter(cmd, "User_id", value.User_id);
            AddParameter(cmd, "Status", value.Status);
            AddParameter(cmd, "Password", value.Password);
            AddParameter(cmd, "Allow_inbound_calls", value.Allow_inbound_calls);
            AddParameter(cmd, "Service_id",
                         value.IsService_idNull ? DBNull.Value : (object)value.Service_id);
            AddParameter(cmd, "Retail_acct_id", value.Retail_acct_id);
            cmd.ExecuteNonQuery();
        }
        /// <summary>
        /// Converts <see cref="System.Data.DataRow"/> to <see cref="ResidentialVoIPRow"/>.
        /// </summary>
        /// <param name="row">The <see cref="System.Data.DataRow"/> object to be mapped.</param>
        /// <returns>A reference to the <see cref="ResidentialVoIPRow"/> object.</returns>
        protected virtual ResidentialVoIPRow MapRow(DataRow row)
        {
            ResidentialVoIPRow mappedObject = new ResidentialVoIPRow();
            DataTable          dataTable    = row.Table;
            DataColumn         dataColumn;

            // Column "User_id"
            dataColumn = dataTable.Columns["User_id"];
            if (!row.IsNull(dataColumn))
            {
                mappedObject.User_id = (string)row[dataColumn];
            }
            // Column "Status"
            dataColumn = dataTable.Columns["Status"];
            if (!row.IsNull(dataColumn))
            {
                mappedObject.Status = (byte)row[dataColumn];
            }
            // Column "Date_first_used"
            dataColumn = dataTable.Columns["Date_first_used"];
            if (!row.IsNull(dataColumn))
            {
                mappedObject.Date_first_used = (System.DateTime)row[dataColumn];
            }
            // Column "Date_last_used"
            dataColumn = dataTable.Columns["Date_last_used"];
            if (!row.IsNull(dataColumn))
            {
                mappedObject.Date_last_used = (System.DateTime)row[dataColumn];
            }
            // Column "Password"
            dataColumn = dataTable.Columns["Password"];
            if (!row.IsNull(dataColumn))
            {
                mappedObject.Password = (string)row[dataColumn];
            }
            // Column "Allow_inbound_calls"
            dataColumn = dataTable.Columns["Allow_inbound_calls"];
            if (!row.IsNull(dataColumn))
            {
                mappedObject.Allow_inbound_calls = (byte)row[dataColumn];
            }
            // Column "Service_id"
            dataColumn = dataTable.Columns["Service_id"];
            if (!row.IsNull(dataColumn))
            {
                mappedObject.Service_id = (short)row[dataColumn];
            }
            // Column "Retail_acct_id"
            dataColumn = dataTable.Columns["Retail_acct_id"];
            if (!row.IsNull(dataColumn))
            {
                mappedObject.Retail_acct_id = (int)row[dataColumn];
            }
            return(mappedObject);
        }
Example #4
0
        internal RetailAccountDto GetByVoIPUserId(Rbr_Db pDb, short pServiceId, string pUserId)
        {
            ResidentialVoIPRow _residentialVoIPRow = pDb.ResidentialVoIPCollection.GetByPrimaryKey(pUserId);

            if (_residentialVoIPRow != null)
            {
                RetailAccountRow _retailAccountRow = pDb.RetailAccountCollection.GetByPrimaryKey(_residentialVoIPRow.Retail_acct_id);
                return(get(pDb, pServiceId, _retailAccountRow));
            }
            return(null);
        }
        /// <summary>
        /// Updates a record in the <c>ResidentialVoIP</c> table.
        /// </summary>
        /// <param name="value">The <see cref="ResidentialVoIPRow"/>
        /// object used to update the table record.</param>
        /// <returns>true if the record was updated; otherwise, false.</returns>
        public virtual bool Update(ResidentialVoIPRow value)
        {
            string sqlStr = "UPDATE [dbo].[ResidentialVoIP] SET " +
                            "[status]=" + _db.CreateSqlParameterName("Status") + ", " +
                            "[password]=" + _db.CreateSqlParameterName("Password") + ", " +
                            "[allow_inbound_calls]=" + _db.CreateSqlParameterName("Allow_inbound_calls") + ", " +
                            "[service_id]=" + _db.CreateSqlParameterName("Service_id") + ", " +
                            "[retail_acct_id]=" + _db.CreateSqlParameterName("Retail_acct_id") +
                            " WHERE " +
                            "[user_id]=" + _db.CreateSqlParameterName("User_id");
            IDbCommand cmd = _db.CreateCommand(sqlStr);

            AddParameter(cmd, "Status", value.Status);
            AddParameter(cmd, "Password", value.Password);
            AddParameter(cmd, "Allow_inbound_calls", value.Allow_inbound_calls);
            AddParameter(cmd, "Service_id",
                         value.IsService_idNull ? DBNull.Value : (object)value.Service_id);
            AddParameter(cmd, "Retail_acct_id", value.Retail_acct_id);
            AddParameter(cmd, "User_id", value.User_id);
            return(0 != cmd.ExecuteNonQuery());
        }
 /// <summary>
 /// Deletes the specified object from the <c>ResidentialVoIP</c> table.
 /// </summary>
 /// <param name="value">The <see cref="ResidentialVoIPRow"/> object to delete.</param>
 /// <returns>true if the record was deleted; otherwise, false.</returns>
 public bool Delete(ResidentialVoIPRow value)
 {
     return(DeleteByPrimaryKey(value.User_id));
 }