ResidentialPSTNDto mapToResidentialPSTN(ResidentialPSTNRow pResidentialPSTNRow) { var _residentialPSTN = new ResidentialPSTNDto(); _residentialPSTN.ANI = pResidentialPSTNRow.ANI; _residentialPSTN.ServiceId = pResidentialPSTNRow.Service_id; _residentialPSTN.Status = pResidentialPSTNRow.AccountStatus; _residentialPSTN.RetailAcctId = pResidentialPSTNRow.Retail_acct_id; if (pResidentialPSTNRow.IsDate_first_usedNull) { _residentialPSTN.DateFirstUsed = pResidentialPSTNRow.Date_first_used; } else { _residentialPSTN.DateFirstUsed = Configuration.Instance.Db.SqlSmallDateTimeMaxValue; } if (pResidentialPSTNRow.IsDate_last_usedNull) { _residentialPSTN.DateLastUsed = pResidentialPSTNRow.Date_last_used; } else { _residentialPSTN.DateLastUsed = Configuration.Instance.Db.SqlSmallDateTimeMaxValue; } return(_residentialPSTN); }
internal RetailAccountDto GetByANI(Rbr_Db pDb, short pServiceId, long pANI) { ResidentialPSTNRow _residentialPSTNRow = pDb.ResidentialPSTNCollection.GetByPrimaryKey(pServiceId, pANI); if (_residentialPSTNRow != null) { RetailAccountRow _retailAccountRow = pDb.RetailAccountCollection.GetByPrimaryKey(_residentialPSTNRow.Retail_acct_id); return(get(pDb, pServiceId, _retailAccountRow)); } return(null); }
/// <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="ResidentialPSTNRow"/> objects.</returns> protected virtual ResidentialPSTNRow[] 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 service_idColumnIndex = reader.GetOrdinal("service_id"); int aniColumnIndex = reader.GetOrdinal("ANI"); int statusColumnIndex = reader.GetOrdinal("status"); int date_first_usedColumnIndex = reader.GetOrdinal("date_first_used"); int date_last_usedColumnIndex = reader.GetOrdinal("date_last_used"); 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) { ResidentialPSTNRow record = new ResidentialPSTNRow(); recordList.Add(record); record.Service_id = Convert.ToInt16(reader.GetValue(service_idColumnIndex)); record.ANI = Convert.ToInt64(reader.GetValue(aniColumnIndex)); 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.Retail_acct_id = Convert.ToInt32(reader.GetValue(retail_acct_idColumnIndex)); if (ri == length && 0 != totalRecordCount) { break; } } } totalRecordCount = 0 == totalRecordCount ? ri + startIndex : -1; return((ResidentialPSTNRow[])(recordList.ToArray(typeof(ResidentialPSTNRow)))); }
internal static void AddResidentialPSTNSubAcct(Rbr_Db pDb, ResidentialPSTNRow pResidentialPSTNRow) { try { pDb.ResidentialPSTNCollection.Insert(pResidentialPSTNRow); } catch (PrimaryKeyException) { throw new ANIAlreadyInUseException(); } catch (Exception _ex) { throw new Exception("Unexpected Error", _ex); } }
public static void Update(string pSalt, RetailAccountDto pRetailAccount) { if (pRetailAccount.AccessEnabled && (pRetailAccount.Person.Salt == null || pRetailAccount.Person.Salt.Trim().Length == 0)) { pRetailAccount.Person.Salt = pSalt; } using (var _db = new Rbr_Db()) { using (var _tx = new Transaction(_db, pSalt, pRetailAccount)) { RetailAccountRow _originalRetailAccountRow = RetailAccountManager.Instance.Get(_db, pRetailAccount.RetailAcctId); RetailAccountRow _retailAccountRow = RetailAccountManager.MapToRetailAccountRow(pRetailAccount); if (_originalRetailAccountRow.AccountStatus != Status.Active && _retailAccountRow.AccountStatus == Status.Active && _retailAccountRow.Date_active == Configuration.Instance.Db.SqlSmallDateTimeMaxValue) { _retailAccountRow.Date_active = DateTime.Today; } if (pRetailAccount.AccessEnabled) { pRetailAccount.Person.RetailAcctId = pRetailAccount.RetailAcctId; PersonManager.Save(_db, pSalt, pRetailAccount.Person); } else { PersonManager.DeleteByRetailAcctId(_db, pRetailAccount.RetailAcctId); } RetailAccountManager.Instance.Update(_db, _retailAccountRow); if (pRetailAccount.PhoneCards != null && pRetailAccount.PhoneCards.Length > 0) { //Update PhoneCard //TODO: now works only with 1 (one) PhoneCard per RetailAcct PhoneCardRow _phoneCardRow = RetailAccountManager.MapToPhoneCardRow(pRetailAccount.PhoneCards[0]); _phoneCardRow.CardStatus = pRetailAccount.Status; RetailAccountManager.UpdatePhoneCard(_db, _phoneCardRow); } if (pRetailAccount.ResidentialPSTNs != null && pRetailAccount.ResidentialPSTNs.Length > 0) { //Update ResidentialPSTN //TODO: now works only with 1 (one) PSTN # per RetailAcct ResidentialPSTNRow _residentialPSTNRow = RetailAccountManager.MapToResidentialPSTNRow(pRetailAccount.ResidentialPSTNs[0]); _residentialPSTNRow.AccountStatus = pRetailAccount.Status; RetailAccountManager.UpdateResidentialPSTNSubAcct(_db, _residentialPSTNRow); } _tx.Commit(); } } }
/// <summary> /// Updates a record in the <c>ResidentialPSTN</c> table. /// </summary> /// <param name="value">The <see cref="ResidentialPSTNRow"/> /// object used to update the table record.</param> /// <returns>true if the record was updated; otherwise, false.</returns> public virtual bool Update(ResidentialPSTNRow value) { string sqlStr = "UPDATE [dbo].[ResidentialPSTN] SET " + "[status]=" + _db.CreateSqlParameterName("Status") + ", " + "[retail_acct_id]=" + _db.CreateSqlParameterName("Retail_acct_id") + " WHERE " + "[service_id]=" + _db.CreateSqlParameterName("Service_id") + " AND " + "[ANI]=" + _db.CreateSqlParameterName("ANI"); IDbCommand cmd = _db.CreateCommand(sqlStr); AddParameter(cmd, "Status", value.Status); AddParameter(cmd, "Retail_acct_id", value.Retail_acct_id); AddParameter(cmd, "Service_id", value.Service_id); AddParameter(cmd, "ANI", value.ANI); return(0 != cmd.ExecuteNonQuery()); }
/// <summary> /// Converts <see cref="System.Data.DataRow"/> to <see cref="ResidentialPSTNRow"/>. /// </summary> /// <param name="row">The <see cref="System.Data.DataRow"/> object to be mapped.</param> /// <returns>A reference to the <see cref="ResidentialPSTNRow"/> object.</returns> protected virtual ResidentialPSTNRow MapRow(DataRow row) { ResidentialPSTNRow mappedObject = new ResidentialPSTNRow(); DataTable dataTable = row.Table; DataColumn dataColumn; // Column "Service_id" dataColumn = dataTable.Columns["Service_id"]; if (!row.IsNull(dataColumn)) { mappedObject.Service_id = (short)row[dataColumn]; } // Column "ANI" dataColumn = dataTable.Columns["ANI"]; if (!row.IsNull(dataColumn)) { mappedObject.ANI = (long)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 "Retail_acct_id" dataColumn = dataTable.Columns["Retail_acct_id"]; if (!row.IsNull(dataColumn)) { mappedObject.Retail_acct_id = (int)row[dataColumn]; } return(mappedObject); }
/// <summary> /// Adds a new record into the <c>ResidentialPSTN</c> table. /// </summary> /// <param name="value">The <see cref="ResidentialPSTNRow"/> object to be inserted.</param> public virtual void Insert(ResidentialPSTNRow value) { string sqlStr = "INSERT INTO [dbo].[ResidentialPSTN] (" + "[service_id], " + "[ANI], " + "[status], " + "[retail_acct_id]" + ") VALUES (" + _db.CreateSqlParameterName("Service_id") + ", " + _db.CreateSqlParameterName("ANI") + ", " + _db.CreateSqlParameterName("Status") + ", " + _db.CreateSqlParameterName("Retail_acct_id") + ")"; IDbCommand cmd = _db.CreateCommand(sqlStr); AddParameter(cmd, "Service_id", value.Service_id); AddParameter(cmd, "ANI", value.ANI); AddParameter(cmd, "Status", value.Status); AddParameter(cmd, "Retail_acct_id", value.Retail_acct_id); cmd.ExecuteNonQuery(); }
internal static ResidentialPSTNRow MapToResidentialPSTNRow(ResidentialPSTNDto pResidentialPSTN) { var _residentialPSTNRow = new ResidentialPSTNRow { AccountStatus = pResidentialPSTN.Status, ANI = pResidentialPSTN.ANI, Service_id = pResidentialPSTN.ServiceId, Retail_acct_id = pResidentialPSTN.RetailAcctId }; if (pResidentialPSTN.DateFirstUsed < Configuration.Instance.Db.SqlSmallDateTimeMaxValue && pResidentialPSTN.DateFirstUsed > DateTime.MinValue) { _residentialPSTNRow.Date_first_used = pResidentialPSTN.DateFirstUsed; } if (pResidentialPSTN.DateLastUsed < Configuration.Instance.Db.SqlSmallDateTimeMaxValue && pResidentialPSTN.DateLastUsed > DateTime.MinValue) { _residentialPSTNRow.Date_last_used = pResidentialPSTN.DateLastUsed; } return(_residentialPSTNRow); }
/// <summary> /// Deletes the specified object from the <c>ResidentialPSTN</c> table. /// </summary> /// <param name="value">The <see cref="ResidentialPSTNRow"/> object to delete.</param> /// <returns>true if the record was deleted; otherwise, false.</returns> public bool Delete(ResidentialPSTNRow value) { return(DeleteByPrimaryKey(value.Service_id, value.ANI)); }
} //TODO: add Serail to all Retail SubAccts? public Residential(RetailAccountRow pRetailAcctRow, ResidentialPSTNRow pResidentialRow) : base(pRetailAcctRow) { residentialPSTNRow = pResidentialRow; }
public static void Add(string pSalt, RetailAccountDto pRetailAccount) { using (var _db = new Rbr_Db()) { using (var _tx = new Transaction(_db, pSalt, pRetailAccount)) { RetailAccountRow _retailAccountRow = RetailAccountManager.MapToRetailAccountRow(pRetailAccount); //TODO: ! CONFIRM IT before implementing // CustomerAcctRow _customerAcctRow = _db.CustomerAcctCollection.GetByPrimaryKey(pRetailAccount.CustomerAcctId); // if (_customerAcctRow.BonusMinutesType == BonusMinutesType.None) { // _retailAccountRow.Current_bonus_minutes = -1; // } _retailAccountRow.Date_created = DateTime.Now; _retailAccountRow.Date_expired = Configuration.Instance.Db.SqlSmallDateTimeMaxValue; _retailAccountRow.Current_balance = _retailAccountRow.Start_balance; _retailAccountRow.Current_bonus_minutes = _retailAccountRow.Start_bonus_minutes; if (_retailAccountRow.AccountStatus == Status.Active) { _retailAccountRow.Date_active = _retailAccountRow.Date_created; } else { _retailAccountRow.Date_active = Configuration.Instance.Db.SqlSmallDateTimeMaxValue; } RetailAccountManager.Instance.Add(_db, _retailAccountRow); pRetailAccount.RetailAcctId = _retailAccountRow.Retail_acct_id; //prepare PhoneCard (s) if (pRetailAccount.PhoneCards != null && pRetailAccount.PhoneCards.Length > 0) { //NOTE: !!! in this virsion only ONE PhoneCard p/RetailAccount allowed!!! if (pRetailAccount.PhoneCards.Length > 1) { throw new Exception("In this virsion only ONE PhoneCard p/RetailAccount allowed!!!"); } foreach (PhoneCardDto _phoneCard in pRetailAccount.PhoneCards) { long _pin = 0; if (_phoneCard.SerialNumber == 0) { ServiceRow _serviceRow = ServiceManager.Get(_db, pRetailAccount.ServiceId); long _serialNumber; generateTestSerialNumberPIN(_db, _serviceRow, out _serialNumber, out _pin); _phoneCard.SerialNumber = _serialNumber; } if (_phoneCard.Pin == 0) { _phoneCard.Pin = _pin; } switch (pRetailAccount.Status) { case Status.Active: _phoneCard.InventoryStatus = InventoryStatus.Activated; break; case Status.Pending: case Status.Blocked: case Status.Archived: case Status.InUse: default: throw new ArgumentException(string.Format("Unexpected Status [{0}]", pRetailAccount.Status)); } _phoneCard.ServiceId = pRetailAccount.ServiceId; _phoneCard.RetailAcctId = pRetailAccount.RetailAcctId; _phoneCard.Status = pRetailAccount.Status; //TODO: ??? set it based on RetAcct status ??? _phoneCard.InventoryStatus = InventoryStatus.Activated; _phoneCard.DateLoaded = _retailAccountRow.Date_created; _phoneCard.DateActive = _retailAccountRow.Date_created; _phoneCard.DateToExpire = _retailAccountRow.Date_to_expire; _phoneCard.DateDeactivated = Configuration.Instance.Db.SqlSmallDateTimeMaxValue; _phoneCard.DateArchived = Configuration.Instance.Db.SqlSmallDateTimeMaxValue; } } //prepare ResidentialPSTN (s) if (pRetailAccount.ResidentialPSTNs != null && pRetailAccount.ResidentialPSTNs.Length > 0) { //NOTE: !!! in this virsion only ONE ResidentialPSTN p/RetailAccount allowed!!! if (pRetailAccount.ResidentialPSTNs.Length > 1) { throw new Exception("In this virsion only ONE ResidentialPSTN p/RetailAccount allowed!!!"); } foreach (var _residentialPSTN in pRetailAccount.ResidentialPSTNs) { _residentialPSTN.Status = pRetailAccount.Status; _residentialPSTN.ServiceId = pRetailAccount.ServiceId; _residentialPSTN.RetailAcctId = pRetailAccount.RetailAcctId; } } ////prepare ResidentialVoIP (s) //if (pRetailAccount.ResidentialVoIPs != null && pRetailAccount.ResidentialVoIPs.Length > 0) { // //NOTE: !!! in this virsion only ONE ResidentialVoIP p/RetailAccount allowed!!! // if (pRetailAccount.ResidentialVoIPs.Length > 1) { // throw new Exception("In this virsion only ONE ResidentialVoIP p/RetailAccount allowed!!!"); // } // foreach (ResidentialVoIP _residentialVoIP in pRetailAccount.ResidentialVoIPs) { // _residentialVoIP.Status = pRetailAccount.Status; // _residentialVoIP.ServiceId = pRetailAccount.ServiceId; // _residentialVoIP.RetailAcctId = pRetailAccount.RetailAcctId; // } //} if (pRetailAccount.AccessEnabled) { pRetailAccount.Person.RetailAcctId = pRetailAccount.RetailAcctId; PersonManager.Save(_db, pSalt, pRetailAccount.Person); } if (pRetailAccount.PhoneCards != null && pRetailAccount.PhoneCards.Length > 0) { //Insert PhoneCard //TODO: now works only with 1 (one) card per RetailAcct PhoneCardRow _phoneCardRow = RetailAccountManager.MapToPhoneCardRow(pRetailAccount.PhoneCards[0]); RetailAccountManager.AddPhoneCard(_db, _phoneCardRow); } if (pRetailAccount.ResidentialPSTNs != null && pRetailAccount.ResidentialPSTNs.Length > 0) { //Insert ResidentialPSTN //TODO: now works only with 1 (one) PSTN # per RetailAcct ResidentialPSTNRow _residentialPSTNRow = RetailAccountManager.MapToResidentialPSTNRow(pRetailAccount.ResidentialPSTNs[0]); RetailAccountManager.AddResidentialPSTNSubAcct(_db, _residentialPSTNRow); } _tx.Commit(); } } }
internal static void UpdateResidentialPSTNSubAcct(Rbr_Db pDb, ResidentialPSTNRow pResidentialPSTNRow) { pDb.ResidentialPSTNCollection.Update(pResidentialPSTNRow); }