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(); } } }
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(); } } }