internal static void Add(Rbr_Db pDb, VirtualSwitchDto pVirtualSwitch) { VirtualSwitchRow _virtualSwitchRow = MapToVirtualSwitchRow(pVirtualSwitch); pDb.VirtualSwitchCollection.Insert(_virtualSwitchRow); pVirtualSwitch.VirtualSwitchId = _virtualSwitchRow.Virtual_switch_id; }
/// <summary> /// Converts <see cref="System.Data.DataRow"/> to <see cref="VirtualSwitchRow"/>. /// </summary> /// <param name="row">The <see cref="System.Data.DataRow"/> object to be mapped.</param> /// <returns>A reference to the <see cref="VirtualSwitchRow"/> object.</returns> protected virtual VirtualSwitchRow MapRow(DataRow row) { VirtualSwitchRow mappedObject = new VirtualSwitchRow(); DataTable dataTable = row.Table; DataColumn dataColumn; // Column "Virtual_switch_id" dataColumn = dataTable.Columns["Virtual_switch_id"]; if (!row.IsNull(dataColumn)) { mappedObject.Virtual_switch_id = (int)row[dataColumn]; } // Column "Name" dataColumn = dataTable.Columns["Name"]; if (!row.IsNull(dataColumn)) { mappedObject.Name = (string)row[dataColumn]; } // Column "Status" dataColumn = dataTable.Columns["Status"]; if (!row.IsNull(dataColumn)) { mappedObject.Status = (byte)row[dataColumn]; } // Column "Contact_info_id" dataColumn = dataTable.Columns["Contact_info_id"]; if (!row.IsNull(dataColumn)) { mappedObject.Contact_info_id = (int)row[dataColumn]; } return(mappedObject); }
static VirtualSwitchDto getInfo(Rbr_Db pDb, VirtualSwitchRow pVirtualSwitchRow) { if (pVirtualSwitchRow == null) { return(null); } ContactInfoDto _contactInfo = ContactInfoManager.Get(pDb, pVirtualSwitchRow.Contact_info_id); return(MapToVirtualSwitch(pVirtualSwitchRow, _contactInfo)); }
/// <summary> /// Updates a record in the <c>VirtualSwitch</c> table. /// </summary> /// <param name="value">The <see cref="VirtualSwitchRow"/> /// object used to update the table record.</param> /// <returns>true if the record was updated; otherwise, false.</returns> public virtual bool Update(VirtualSwitchRow value) { string sqlStr = "UPDATE [dbo].[VirtualSwitch] SET " + "[name]=" + _db.CreateSqlParameterName("Name") + ", " + "[status]=" + _db.CreateSqlParameterName("Status") + ", " + "[contact_info_id]=" + _db.CreateSqlParameterName("Contact_info_id") + " WHERE " + "[virtual_switch_id]=" + _db.CreateSqlParameterName("Virtual_switch_id"); IDbCommand cmd = _db.CreateCommand(sqlStr); AddParameter(cmd, "Name", value.Name); AddParameter(cmd, "Status", value.Status); AddParameter(cmd, "Contact_info_id", value.Contact_info_id); AddParameter(cmd, "Virtual_switch_id", value.Virtual_switch_id); return(0 != cmd.ExecuteNonQuery()); }
internal static VirtualSwitchDto MapToVirtualSwitch(VirtualSwitchRow pVirtualSwitchRow, ContactInfoDto pContactInfo) { if (pVirtualSwitchRow == null) { return(null); } var _virtualSwitch = new VirtualSwitchDto(); _virtualSwitch.VirtualSwitchId = pVirtualSwitchRow.Virtual_switch_id; _virtualSwitch.Name = pVirtualSwitchRow.Name; _virtualSwitch.Status = pVirtualSwitchRow.SwitchStatus; _virtualSwitch.ContactInfo = pContactInfo; return(_virtualSwitch); }
/// <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="VirtualSwitchRow"/> objects.</returns> protected virtual VirtualSwitchRow[] 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 virtual_switch_idColumnIndex = reader.GetOrdinal("virtual_switch_id"); int nameColumnIndex = reader.GetOrdinal("name"); int statusColumnIndex = reader.GetOrdinal("status"); int contact_info_idColumnIndex = reader.GetOrdinal("contact_info_id"); System.Collections.ArrayList recordList = new System.Collections.ArrayList(); int ri = -startIndex; while (reader.Read()) { ri++; if (ri > 0 && ri <= length) { VirtualSwitchRow record = new VirtualSwitchRow(); recordList.Add(record); record.Virtual_switch_id = Convert.ToInt32(reader.GetValue(virtual_switch_idColumnIndex)); record.Name = Convert.ToString(reader.GetValue(nameColumnIndex)); record.Status = Convert.ToByte(reader.GetValue(statusColumnIndex)); record.Contact_info_id = Convert.ToInt32(reader.GetValue(contact_info_idColumnIndex)); if (ri == length && 0 != totalRecordCount) { break; } } } totalRecordCount = 0 == totalRecordCount ? ri + startIndex : -1; return((VirtualSwitchRow[])(recordList.ToArray(typeof(VirtualSwitchRow)))); }
internal static VirtualSwitchRow MapToVirtualSwitchRow(VirtualSwitchDto pVirtualSwitch) { if (pVirtualSwitch == null) { return(null); } var _virtualSwitchRow = new VirtualSwitchRow(); _virtualSwitchRow.Virtual_switch_id = pVirtualSwitch.VirtualSwitchId; _virtualSwitchRow.Name = pVirtualSwitch.Name; _virtualSwitchRow.SwitchStatus = pVirtualSwitch.Status; if (pVirtualSwitch.ContactInfo != null) { _virtualSwitchRow.Contact_info_id = pVirtualSwitch.ContactInfoId; } return(_virtualSwitchRow); }
/// <summary> /// Adds a new record into the <c>VirtualSwitch</c> table. /// </summary> /// <param name="value">The <see cref="VirtualSwitchRow"/> object to be inserted.</param> public virtual void Insert(VirtualSwitchRow value) { string sqlStr = "INSERT INTO [dbo].[VirtualSwitch] (" + "[virtual_switch_id], " + "[name], " + "[status], " + "[contact_info_id]" + ") VALUES (" + _db.CreateSqlParameterName("Virtual_switch_id") + ", " + _db.CreateSqlParameterName("Name") + ", " + _db.CreateSqlParameterName("Status") + ", " + _db.CreateSqlParameterName("Contact_info_id") + ")"; IDbCommand cmd = _db.CreateCommand(sqlStr); AddParameter(cmd, "Virtual_switch_id", value.Virtual_switch_id); AddParameter(cmd, "Name", value.Name); AddParameter(cmd, "Status", value.Status); AddParameter(cmd, "Contact_info_id", value.Contact_info_id); cmd.ExecuteNonQuery(); }
internal static void Update(Rbr_Db pDb, VirtualSwitchDto pVirtualSwitch) { VirtualSwitchRow _virtualSwitchRow = MapToVirtualSwitchRow(pVirtualSwitch); pDb.VirtualSwitchCollection.Update(_virtualSwitchRow); }
static VirtualSwitchDto get(Rbr_Db pDb, int pVirtualSwitchId) { VirtualSwitchRow _virtualSwitchRow = pDb.VirtualSwitchCollection.GetByPrimaryKey(pVirtualSwitchId); return(getInfo(pDb, _virtualSwitchRow)); }
/// <summary> /// Deletes the specified object from the <c>VirtualSwitch</c> table. /// </summary> /// <param name="value">The <see cref="VirtualSwitchRow"/> object to delete.</param> /// <returns>true if the record was deleted; otherwise, false.</returns> public bool Delete(VirtualSwitchRow value) { return(DeleteByPrimaryKey(value.Virtual_switch_id)); }