/// <summary> /// Converts <see cref="System.Data.DataRow"/> to <see cref="DialPeerRow"/>. /// </summary> /// <param name="row">The <see cref="System.Data.DataRow"/> object to be mapped.</param> /// <returns>A reference to the <see cref="DialPeerRow"/> object.</returns> protected virtual DialPeerRow MapRow(DataRow row) { DialPeerRow mappedObject = new DialPeerRow(); DataTable dataTable = row.Table; DataColumn dataColumn; // Column "End_point_id" dataColumn = dataTable.Columns["End_point_id"]; if (!row.IsNull(dataColumn)) { mappedObject.End_point_id = (short)row[dataColumn]; } // Column "Prefix_in" dataColumn = dataTable.Columns["Prefix_in"]; if (!row.IsNull(dataColumn)) { mappedObject.Prefix_in = (string)row[dataColumn]; } // Column "Customer_acct_id" dataColumn = dataTable.Columns["Customer_acct_id"]; if (!row.IsNull(dataColumn)) { mappedObject.Customer_acct_id = (short)row[dataColumn]; } return(mappedObject); }
public static IList <CustomerDialPeer> GetAll(IConfiguration pConfiguration, ILogger pLogger) { var _dialPeerRows = new DialPeerRow[] {}; try { using (var _db = new Rbr_Db()) { _dialPeerRows = _db.DialPeerCollection.GetAll(); } } catch (Exception _ex) { pLogger.LogRbr(LogSeverity.Critical, "CustomerDialPeer.GetAll", string.Format("Exception:\r\n{0}", _ex)); } if (_dialPeerRows == null || _dialPeerRows.Length == 0) { throw new Exception("No Customer DialPeers FOUND in Db"); } var _customerDialPeers = new List <CustomerDialPeer>(); foreach (var _dialPeerRow in _dialPeerRows) { _customerDialPeers.Add(new CustomerDialPeer(_dialPeerRow)); } return(_customerDialPeers); }
/// <summary> /// Updates a record in the <c>DialPeer</c> table. /// </summary> /// <param name="value">The <see cref="DialPeerRow"/> /// object used to update the table record.</param> /// <returns>true if the record was updated; otherwise, false.</returns> public virtual bool Update(DialPeerRow value) { string sqlStr = "UPDATE [dbo].[DialPeer] SET " + "[customer_acct_id]=" + _db.CreateSqlParameterName("Customer_acct_id") + " WHERE " + "[end_point_id]=" + _db.CreateSqlParameterName("End_point_id") + " AND " + "[prefix_in]=" + _db.CreateSqlParameterName("Prefix_in"); IDbCommand cmd = _db.CreateCommand(sqlStr); AddParameter(cmd, "Customer_acct_id", value.Customer_acct_id); AddParameter(cmd, "End_point_id", value.End_point_id); AddParameter(cmd, "Prefix_in", value.Prefix_in); return(0 != cmd.ExecuteNonQuery()); }
public static void AddEndpoint(EndPointRow pEndPointRow, EndpointContext pEndpointContext) { using (var _db = new Rbr_Db()) { using (var _tx = new Transaction(_db, pEndPointRow, pEndpointContext)) { //TODO: NEW DAL - VirtualSwitch pEndPointRow.Virtual_switch_id = AppConstants.DefaultVirtualSwitchId; EndpointManager.Add(_db, pEndPointRow, pEndpointContext); //CarrierAcctManager.AddDialPeer(_db, pEndPointRow, pEndpointContext); if (pEndpointContext.CarrierAcctEPMapRowToAdd != null && pEndpointContext.CarrierAcctEPMapRowToAdd.Length > 0) { foreach (var _carrierAcctEPMapRow in pEndpointContext.CarrierAcctEPMapRowToAdd) { _carrierAcctEPMapRow.End_point_id = pEndPointRow.End_point_id; CarrierAcctManager.AddDialPeer(_db, _carrierAcctEPMapRow, pEndPointRow); } } if (pEndpointContext.CustomerAcct != null) { if (pEndpointContext.CustomerAcct.ServiceDto.AccessNumbers != null && pEndpointContext.CustomerAcct.ServiceDto.AccessNumbers.Length > 0) { foreach (var _accessNumber in pEndpointContext.CustomerAcct.ServiceDto.AccessNumbers) { var _newDialPeer = new DialPeerRow { End_point_id = pEndPointRow.End_point_id, Prefix_in = _accessNumber.Number.ToString(), Customer_acct_id = pEndpointContext.CustomerAcct.CustomerAcctId }; CustomerAcctManager.AddDialPeer(_db, _newDialPeer, pEndPointRow); } } else { var _newDialPeer = new DialPeerRow { End_point_id = pEndPointRow.End_point_id, Prefix_in = pEndpointContext.CustomerAcct.PrefixIn, Customer_acct_id = pEndpointContext.CustomerAcct.CustomerAcctId }; CustomerAcctManager.AddDialPeer(_db, _newDialPeer, pEndPointRow); } } _tx.Commit(); } } }
/// <summary> /// Adds a new record into the <c>DialPeer</c> table. /// </summary> /// <param name="value">The <see cref="DialPeerRow"/> object to be inserted.</param> public virtual void Insert(DialPeerRow value) { string sqlStr = "INSERT INTO [dbo].[DialPeer] (" + "[end_point_id], " + "[prefix_in], " + "[customer_acct_id]" + ") VALUES (" + _db.CreateSqlParameterName("End_point_id") + ", " + _db.CreateSqlParameterName("Prefix_in") + ", " + _db.CreateSqlParameterName("Customer_acct_id") + ")"; IDbCommand cmd = _db.CreateCommand(sqlStr); AddParameter(cmd, "End_point_id", value.End_point_id); AddParameter(cmd, "Prefix_in", value.Prefix_in); AddParameter(cmd, "Customer_acct_id", value.Customer_acct_id); cmd.ExecuteNonQuery(); }
static void attachAccessNumbers(Rbr_Db pDb, CustomerAcctDto pCustomerAcct, IEnumerable <AccessNumberListRow> pAccessNumberRowsFromView) { foreach (var _accessNumberRowFromView in pAccessNumberRowsFromView) { _accessNumberRowFromView.Customer_acct_id = pCustomerAcct.CustomerAcctId; _accessNumberRowFromView.Service_id = pCustomerAcct.ServiceDto.ServiceId; var _accessNumberRowFromDb = pDb.AccessNumberListCollection.GetByPrimaryKey(_accessNumberRowFromView.Access_number); if (_accessNumberRowFromDb == null || _accessNumberRowFromDb.IsCustomer_acct_idNull) { pDb.AccessNumberListCollection.Insert(_accessNumberRowFromView); //-- Add retail_dial_peers var _endpointRows = pDb.EndPointCollection.GetByCustomerAcctId(pCustomerAcct.CustomerAcctId, new[] { Status.Pending, Status.Active, Status.Blocked, Status.Archived }); foreach (var _endpointRow in _endpointRows) { var _dialPeerRow = new DialPeerRow { End_point_id = _endpointRow.End_point_id, Prefix_in = _accessNumberRowFromView.Access_number.ToString(), Customer_acct_id = pCustomerAcct.CustomerAcctId }; CustomerAcctManager.AddDialPeer(pDb, _dialPeerRow, _endpointRow); } continue; } if (_accessNumberRowFromDb.Customer_acct_id != pCustomerAcct.CustomerAcctId) { var _otherCustomerAcctRow = pDb.CustomerAcctCollection.GetByPrimaryKey(_accessNumberRowFromDb.Customer_acct_id); throw new Exception(string.Format("Access Number={0} already in use by other Customer Account={1}", _accessNumberRowFromView.Access_number, _otherCustomerAcctRow.Name)); } _accessNumberRowFromDb.Customer_acct_id = pCustomerAcct.CustomerAcctId; _accessNumberRowFromDb.Service_id = pCustomerAcct.ServiceDto.ServiceId; _accessNumberRowFromDb.ScriptType = _accessNumberRowFromView.ScriptType; _accessNumberRowFromDb.ScriptLanguage = _accessNumberRowFromView.ScriptLanguage; _accessNumberRowFromDb.Surcharge = _accessNumberRowFromView.Surcharge; _accessNumberRowFromDb.SurchargeType = _accessNumberRowFromView.SurchargeType; pDb.AccessNumberListCollection.Update(_accessNumberRowFromDb); //pDb.AddChangedObject(new AccessNumberKey(TxType.Delete, _accessNumberRowFromDb.Access_number)); } }
public static void AddDialPeersForEndpoint(short pEndpointId, string pPrefix, short pCustomerAcctId, RetailType pRetailType) { using (var _db = new Rbr_Db()) { using (var _tx = new Transaction(_db, pEndpointId, pPrefix, pCustomerAcctId, pRetailType)) { var _endpointRow = EndpointManager.Get(_db, pEndpointId); if (_endpointRow == null) { throw new Exception(string.Format("Endpoint NOT FOUND, EndpointId={0}", pEndpointId)); } var _dialPeerRow = CustomerAcctManager.GetDialPeerRow(_db, pEndpointId, pPrefix); if (_dialPeerRow == null) { _dialPeerRow = new DialPeerRow { End_point_id = pEndpointId, Prefix_in = pPrefix, Customer_acct_id = pCustomerAcctId }; CustomerAcctManager.AddDialPeer(_db, _dialPeerRow, _endpointRow); } //-- If Retail, add accessNumber DialPeers if (pRetailType == RetailType.PhoneCard || pRetailType == RetailType.Residential) { var _accessNumberRows = ServiceManager.GetAccessNumbers(_db, pCustomerAcctId); foreach (var _accessNumberRow in _accessNumberRows) { _dialPeerRow = new DialPeerRow { End_point_id = pEndpointId, Prefix_in = _accessNumberRow.Access_number.ToString(), Customer_acct_id = pCustomerAcctId }; CustomerAcctManager.AddDialPeer(_db, _dialPeerRow, _endpointRow); } } _tx.Commit(); } } }
/// <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="DialPeerRow"/> objects.</returns> protected virtual DialPeerRow[] 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 end_point_idColumnIndex = reader.GetOrdinal("end_point_id"); int prefix_inColumnIndex = reader.GetOrdinal("prefix_in"); int customer_acct_idColumnIndex = reader.GetOrdinal("customer_acct_id"); System.Collections.ArrayList recordList = new System.Collections.ArrayList(); int ri = -startIndex; while (reader.Read()) { ri++; if (ri > 0 && ri <= length) { DialPeerRow record = new DialPeerRow(); recordList.Add(record); record.End_point_id = Convert.ToInt16(reader.GetValue(end_point_idColumnIndex)); record.Prefix_in = Convert.ToString(reader.GetValue(prefix_inColumnIndex)); record.Customer_acct_id = Convert.ToInt16(reader.GetValue(customer_acct_idColumnIndex)); if (ri == length && 0 != totalRecordCount) { break; } } } totalRecordCount = 0 == totalRecordCount ? ri + startIndex : -1; return((DialPeerRow[])(recordList.ToArray(typeof(DialPeerRow)))); }
public static void AddDialPeers(EndPointRow[] pEndpointRows, CustomerAcctDto pCustomerAcct) { using (var _db = new Rbr_Db()) { using (var _tx = new Transaction(_db, pEndpointRows, pCustomerAcct)) { foreach (var _endPointRow in pEndpointRows) { if (pCustomerAcct != null) { var _newDialPeer = new DialPeerRow { End_point_id = _endPointRow.End_point_id, Prefix_in = pCustomerAcct.PrefixIn, Customer_acct_id = pCustomerAcct.CustomerAcctId }; CustomerAcctManager.AddDialPeer(_db, _newDialPeer, _endPointRow); } } _tx.Commit(); } } }
public static void ReassignDialPeer(EndPointRow pEndpointRow, CustomerAcctDto pFromCustomerAcct, CustomerAcctDto pToCustomerAcct) { if (pEndpointRow.WithInPrefixes || pFromCustomerAcct.WithPrefixes || pToCustomerAcct.WithPrefixes) { throw new Exception("Invalid operation: expecting Endpoint and Customer without Prefixes ONLY."); } using (var _db = new Rbr_Db()) { using (var _tx = new Transaction(_db, pEndpointRow, pFromCustomerAcct, pToCustomerAcct)) { CustomerAcctManager.DeleteDialPeer(_db, pEndpointRow.End_point_id, pFromCustomerAcct.PrefixIn); var _newDialPeerRow = new DialPeerRow { End_point_id = pEndpointRow.End_point_id, Prefix_in = pToCustomerAcct.PrefixIn, Customer_acct_id = pToCustomerAcct.CustomerAcctId }; CustomerAcctManager.AddDialPeer(_db, _newDialPeerRow, pEndpointRow); _tx.Commit(); } } }
public static void AddChangingEndpointPrefixType(EndPointRow pEndpointRow, CustomerAcctDto pCustomerAcct) { using (var _db = new Rbr_Db()) { using (var _tx = new Transaction(_db, pEndpointRow, pCustomerAcct)) { EndpointManager.UpdatePrefixType(_db, pEndpointRow, pCustomerAcct.PrefixInTypeId); var _endpointContext = new EndpointContext { CustomerAcct = pCustomerAcct }; if (_endpointContext.CustomerAcct != null) { var _newDialPeer = new DialPeerRow { End_point_id = pEndpointRow.End_point_id, Prefix_in = _endpointContext.CustomerAcct.PrefixIn, Customer_acct_id = _endpointContext.CustomerAcct.CustomerAcctId }; CustomerAcctManager.AddDialPeer(_db, _newDialPeer, pEndpointRow); } _tx.Commit(); } } }
internal static void AddDialPeer(Rbr_Db pDb, DialPeerRow pDialPeerRow, EndPointRow pEndPointRow) { pDb.DialPeerCollection.Insert(pDialPeerRow); //pDb.AddChangedObject(new EndpointKey(TxType.Add, pDialPeerRow.End_point_id)); }
public CustomerDialPeer(DialPeerRow pDialPeerRow) { dialPeerRow = pDialPeerRow; }
/// <summary> /// Deletes the specified object from the <c>DialPeer</c> table. /// </summary> /// <param name="value">The <see cref="DialPeerRow"/> object to delete.</param> /// <returns>true if the record was deleted; otherwise, false.</returns> public bool Delete(DialPeerRow value) { return(DeleteByPrimaryKey(value.End_point_id, value.Prefix_in)); }