/// <summary>
        /// Adds a new record into the <c>CustomerSupportGroup</c> table.
        /// </summary>
        /// <param name="value">The <see cref="CustomerSupportGroupRow"/> object to be inserted.</param>
        public virtual void Insert(CustomerSupportGroupRow value)
        {
            string sqlStr = "INSERT INTO [dbo].[CustomerSupportGroup] (" +
                            "[group_id], " +
                            "[description], " +
                            "[role], " +
                            "[max_amount], " +
                            "[allow_status_change], " +
                            "[vendor_id]" +
                            ") VALUES (" +
                            _db.CreateSqlParameterName("Group_id") + ", " +
                            _db.CreateSqlParameterName("Description") + ", " +
                            _db.CreateSqlParameterName("Role") + ", " +
                            _db.CreateSqlParameterName("Max_amount") + ", " +
                            _db.CreateSqlParameterName("Allow_status_change") + ", " +
                            _db.CreateSqlParameterName("Vendor_id") + ")";
            IDbCommand cmd = _db.CreateCommand(sqlStr);

            AddParameter(cmd, "Group_id", value.Group_id);
            AddParameter(cmd, "Description", value.Description);
            AddParameter(cmd, "Role", value.Role);
            AddParameter(cmd, "Max_amount", value.Max_amount);
            AddParameter(cmd, "Allow_status_change", value.Allow_status_change);
            AddParameter(cmd, "Vendor_id", value.Vendor_id);
            cmd.ExecuteNonQuery();
        }
        internal static void DeleteCustomerSupportGroup(Rbr_Db pDb, int pGroupId)
        {
            CustomerSupportGroupRow _customerSupportGroupRow = pDb.CustomerSupportGroupCollection.GetByPrimaryKey(pGroupId);

            PersonRow[] _personRows = pDb.PersonCollection.GetByGroup_id(pGroupId);
            foreach (PersonRow _personRow in _personRows)
            {
                if (RetailAccountManager.HasPayments(pDb, _personRow.Person_id))
                {
                    throw new InvalidOperationException("Cannot Delete Group [" + _customerSupportGroupRow.Description + "]; At least one Representative [Login="******"] in this Group has a Payment History.");
                }
            }
            pDb.PersonCollection.DeleteByGroup_id(pGroupId);
            pDb.CustomerSupportGroupCollection.DeleteByPrimaryKey(pGroupId);
        }
        /// <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="CustomerSupportGroupRow"/> objects.</returns>
        protected virtual CustomerSupportGroupRow[] 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 group_idColumnIndex            = reader.GetOrdinal("group_id");
            int descriptionColumnIndex         = reader.GetOrdinal("description");
            int roleColumnIndex                = reader.GetOrdinal("role");
            int max_amountColumnIndex          = reader.GetOrdinal("max_amount");
            int allow_status_changeColumnIndex = reader.GetOrdinal("allow_status_change");
            int vendor_idColumnIndex           = reader.GetOrdinal("vendor_id");

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

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

                    record.Group_id            = Convert.ToInt32(reader.GetValue(group_idColumnIndex));
                    record.Description         = Convert.ToString(reader.GetValue(descriptionColumnIndex));
                    record.Role                = Convert.ToInt32(reader.GetValue(roleColumnIndex));
                    record.Max_amount          = Convert.ToDecimal(reader.GetValue(max_amountColumnIndex));
                    record.Allow_status_change = Convert.ToByte(reader.GetValue(allow_status_changeColumnIndex));
                    record.Vendor_id           = Convert.ToInt32(reader.GetValue(vendor_idColumnIndex));

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

            totalRecordCount = 0 == totalRecordCount ? ri + startIndex : -1;
            return((CustomerSupportGroupRow[])(recordList.ToArray(typeof(CustomerSupportGroupRow))));
        }
        static internal CustomerSupportGroupDto mapToCustomerSupportGroup(CustomerSupportGroupRow pCustomerSupportGroupRow)
        {
            if (pCustomerSupportGroupRow == null)
            {
                return(null);
            }
            CustomerSupportGroupDto _customerSupportGroup = new CustomerSupportGroupDto();

            _customerSupportGroup.GroupId           = pCustomerSupportGroupRow.Group_id;
            _customerSupportGroup.Description       = pCustomerSupportGroupRow.Description;
            _customerSupportGroup.GroupRole         = pCustomerSupportGroupRow.GroupRole;
            _customerSupportGroup.MaxAmount         = pCustomerSupportGroupRow.Max_amount;
            _customerSupportGroup.AllowStatusChange = pCustomerSupportGroupRow.AllowStatusChange;
            _customerSupportGroup.VendorId          = pCustomerSupportGroupRow.Vendor_id;

            return(_customerSupportGroup);
        }
        /// <summary>
        /// Converts <see cref="System.Data.DataRow"/> to <see cref="CustomerSupportGroupRow"/>.
        /// </summary>
        /// <param name="row">The <see cref="System.Data.DataRow"/> object to be mapped.</param>
        /// <returns>A reference to the <see cref="CustomerSupportGroupRow"/> object.</returns>
        protected virtual CustomerSupportGroupRow MapRow(DataRow row)
        {
            CustomerSupportGroupRow mappedObject = new CustomerSupportGroupRow();
            DataTable  dataTable = row.Table;
            DataColumn dataColumn;

            // Column "Group_id"
            dataColumn = dataTable.Columns["Group_id"];
            if (!row.IsNull(dataColumn))
            {
                mappedObject.Group_id = (int)row[dataColumn];
            }
            // Column "Description"
            dataColumn = dataTable.Columns["Description"];
            if (!row.IsNull(dataColumn))
            {
                mappedObject.Description = (string)row[dataColumn];
            }
            // Column "Role"
            dataColumn = dataTable.Columns["Role"];
            if (!row.IsNull(dataColumn))
            {
                mappedObject.Role = (int)row[dataColumn];
            }
            // Column "Max_amount"
            dataColumn = dataTable.Columns["Max_amount"];
            if (!row.IsNull(dataColumn))
            {
                mappedObject.Max_amount = (decimal)row[dataColumn];
            }
            // Column "Allow_status_change"
            dataColumn = dataTable.Columns["Allow_status_change"];
            if (!row.IsNull(dataColumn))
            {
                mappedObject.Allow_status_change = (byte)row[dataColumn];
            }
            // Column "Vendor_id"
            dataColumn = dataTable.Columns["Vendor_id"];
            if (!row.IsNull(dataColumn))
            {
                mappedObject.Vendor_id = (int)row[dataColumn];
            }
            return(mappedObject);
        }
        /// <summary>
        /// Updates a record in the <c>CustomerSupportGroup</c> table.
        /// </summary>
        /// <param name="value">The <see cref="CustomerSupportGroupRow"/>
        /// object used to update the table record.</param>
        /// <returns>true if the record was updated; otherwise, false.</returns>
        public virtual bool Update(CustomerSupportGroupRow value)
        {
            string sqlStr = "UPDATE [dbo].[CustomerSupportGroup] SET " +
                            "[description]=" + _db.CreateSqlParameterName("Description") + ", " +
                            "[role]=" + _db.CreateSqlParameterName("Role") + ", " +
                            "[max_amount]=" + _db.CreateSqlParameterName("Max_amount") + ", " +
                            "[allow_status_change]=" + _db.CreateSqlParameterName("Allow_status_change") + ", " +
                            "[vendor_id]=" + _db.CreateSqlParameterName("Vendor_id") +
                            " WHERE " +
                            "[group_id]=" + _db.CreateSqlParameterName("Group_id");
            IDbCommand cmd = _db.CreateCommand(sqlStr);

            AddParameter(cmd, "Description", value.Description);
            AddParameter(cmd, "Role", value.Role);
            AddParameter(cmd, "Max_amount", value.Max_amount);
            AddParameter(cmd, "Allow_status_change", value.Allow_status_change);
            AddParameter(cmd, "Vendor_id", value.Vendor_id);
            AddParameter(cmd, "Group_id", value.Group_id);
            return(0 != cmd.ExecuteNonQuery());
        }
 internal static void SaveCustomerSupportGroup(Rbr_Db pDb, CustomerSupportGroupDto pCustomerSupportGroup)
 {
     try {
         CustomerSupportGroupRow _customerSupportGroupRow = mapToCustomerSupportGroupRow(pCustomerSupportGroup);
         if (_customerSupportGroupRow != null)
         {
             if (_customerSupportGroupRow.Group_id == 0)
             {
                 pDb.CustomerSupportGroupCollection.Insert(_customerSupportGroupRow);
                 pCustomerSupportGroup.GroupId = _customerSupportGroupRow.Group_id;
             }
             else
             {
                 pDb.CustomerSupportGroupCollection.Update(_customerSupportGroupRow);
             }
         }
     }
     catch (AlternateKeyException) {
         throw new LoginNameAlreadyInUseException();
     }
 }
        //public static CustomerAcctSupportMap Get(short pCustomerAcctId, int pVendorId) {
        //  using (Rbr_Db _db = new Rbr_Db()) {
        //    return Get(_db, pCustomerAcctId, pVendorId);
        //  }
        //}

        //public static CustomerAcctSupportMap[] GetAll(int pVendorId) {
        //  using (Rbr_Db _db = new Rbr_Db()) {
        //    return GetAll(_db, pVendorId);
        //  }
        //}

        internal static CustomerSupportGroupDto GetCustomerSupportGroup(Rbr_Db pDb, int pCustomerSupportGroupId)
        {
            CustomerSupportGroupRow _customerSupportGroupRow = pDb.CustomerSupportGroupCollection.GetByPrimaryKey(pCustomerSupportGroupId);

            return(mapToCustomerSupportGroup(_customerSupportGroupRow));
        }
 /// <summary>
 /// Deletes the specified object from the <c>CustomerSupportGroup</c> table.
 /// </summary>
 /// <param name="value">The <see cref="CustomerSupportGroupRow"/> object to delete.</param>
 /// <returns>true if the record was deleted; otherwise, false.</returns>
 public bool Delete(CustomerSupportGroupRow value)
 {
     return(DeleteByPrimaryKey(value.Group_id));
 }