public static RetailAccountDto GetBySerialNumber(short pServiceId, long pSerialNumber)
 {
     using (var _db = new Rbr_Db()) {
         RetailAccountDto _retailAccount = RetailAccountManager.Instance.GetBySerialNumber(_db, pServiceId, pSerialNumber);
         if (_retailAccount != null && _retailAccount.ServiceId != pServiceId)
         {
             return(null);
         }
         return(_retailAccount);
     }
 }
 public static void Delete(RetailAccountDto pRetailAccount)
 {
     using (var _db = new Rbr_Db()) {
         using (var _tx = new Transaction(_db, pRetailAccount)) {
             RetailAccountManager.DeletePhoneCard(_db, pRetailAccount.RetailAcctId);
             RetailAccountManager.DeleteResidentialPSTNSubAcct(_db, pRetailAccount.RetailAcctId);
             PersonManager.DeleteByRetailAcctId(_db, pRetailAccount.RetailAcctId);
             RetailAccountManager.Instance.Delete(_db, pRetailAccount);
             _tx.Commit();
         }
     }
 }
        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();
                }
            }
        }
Пример #4
0
        RetailAccountDto get(Rbr_Db pDb, short pServiceId, RetailAccountRow pRetailAccountRow)
        {
            if (pRetailAccountRow != null)
            {
                ServiceRow       _serviceRow    = ServiceManager.Get(pDb, pServiceId);
                RetailAccountDto _retailAccount = mapToRetailAccount(pRetailAccountRow);
                _retailAccount.ServiceId  = pServiceId;
                _retailAccount.RetailType = _serviceRow.RetailType;

                _retailAccount.Person = PersonManager.GetByRetailAcctId(pDb, pRetailAccountRow.Retail_acct_id);

                PhoneCardDto[] _phoneCards = mapToPhoneCards(pDb.PhoneCardCollection.GetByRetail_acct_id(_retailAccount.RetailAcctId));
                if (_phoneCards != null && _phoneCards.Length > 0)
                {
                    _retailAccount.PhoneCards = _phoneCards;
                    foreach (PhoneCardDto _phoneCard in _phoneCards)
                    {
                        if (_retailAccount.ServiceId != _phoneCard.ServiceId)
                        {
                            throw new Exception("Retail Account has a card from a different Service. [RetailAcctId=" + _retailAccount.RetailAcctId + "] [RetailAccount.ServiceId=" + _retailAccount.ServiceId + "] [PhoneCard.ServiceId=" + _phoneCard.ServiceId + "]");
                        }
                    }
                }

                ResidentialPSTNDto[] _residentialPSTNs = mapToResidentialPSTNs(pDb.ResidentialPSTNCollection.GetByRetail_acct_id(_retailAccount.RetailAcctId));
                if (_residentialPSTNs != null && _residentialPSTNs.Length > 0)
                {
                    _retailAccount.ResidentialPSTNs = _residentialPSTNs;
                    foreach (ResidentialPSTNDto _residentialPSTN in _residentialPSTNs)
                    {
                        if (_retailAccount.ServiceId != _residentialPSTN.ServiceId)
                        {
                            throw new Exception("Retail Account has a ResidentialPSTN from a different Service. [RetailAcctId=" + _retailAccount.RetailAcctId + "] [RetailAccount.ServiceId=" + _retailAccount.ServiceId + "] [ResidentialPSTN.ServiceId=" + _residentialPSTN.ServiceId + "]");
                        }
                    }
                }

                //ResidentialVoIP[] _residentialVoIPs = mapToResidentialVoIPs(pDb.ResidentialVoIPCollection.GetByRetail_acct_id(_retailAccount.RetailAcctId));
                //if (_residentialVoIPs != null && _residentialVoIPs.Length > 0) {
                //  _retailAccount.ResidentialVoIPs = _residentialVoIPs;
                //  foreach (ResidentialVoIP _residentialVoIP in _residentialVoIPs) {
                //    if (_retailAccount.ServiceId != _residentialVoIP.ServiceId) {
                //      throw new Exception("Retail Account has a ResidentialVoIP from a different Service. [RetailAcctId=" + _retailAccount.RetailAcctId + "] [RetailAccount.ServiceId=" + _retailAccount.ServiceId + "] [ResidentialVoIP.ServiceId=" + _residentialVoIP.ServiceId + "]");
                //    }
                //  }
                //}
                return(_retailAccount);
            }
            return(null);
        }
        public static void Save(RetailAccountDto pRetailAccount)
        {
            //IMPORTANT: !!! SALT MUST BE THE SAME ON ALL SERVERS !!!
            //IMPORTANT: !!! SALT MUST BE SET ONLY ONCE !!!
            //that's why it's set outside of the transaction, so we can replicate it to other servers
            string _salt = SaltHashedPwd.CreateRandomSalt();

            if (pRetailAccount.RetailAcctId == 0)
            {
                Add(_salt, pRetailAccount);
            }
            else
            {
                Update(_salt, pRetailAccount);
            }
        }
Пример #6
0
        RetailAccountDto mapToRetailAccount(RetailAccountRow pRetailAccountRow)
        {
            var _retailAccount = new RetailAccountDto();

            _retailAccount.CurrentBalance      = pRetailAccountRow.Current_balance;
            _retailAccount.CurrentBonusMinutes = pRetailAccountRow.Current_bonus_minutes;
            _retailAccount.CustomerAcctId      = pRetailAccountRow.Customer_acct_id;
            _retailAccount.DateActive          = pRetailAccountRow.Date_active;
            _retailAccount.DateCreated         = pRetailAccountRow.Date_created;
            _retailAccount.DateExpired         = pRetailAccountRow.Date_expired;
            _retailAccount.DateToExpire        = pRetailAccountRow.Date_to_expire;
            _retailAccount.RetailAcctId        = pRetailAccountRow.Retail_acct_id;
            _retailAccount.StartBalance        = pRetailAccountRow.Start_balance;
            _retailAccount.StartBonusMinutes   = pRetailAccountRow.Start_bonus_minutes;
            _retailAccount.Status = pRetailAccountRow.AccountStatus;

            return(_retailAccount);
        }
Пример #7
0
        internal static RetailAccountRow MapToRetailAccountRow(RetailAccountDto pRetailAccount)
        {
            var _retailAccountRow = new RetailAccountRow
            {
                AccountStatus         = pRetailAccount.Status,
                Current_balance       = pRetailAccount.CurrentBalance,
                Current_bonus_minutes = pRetailAccount.CurrentBonusMinutes,
                Date_active           = pRetailAccount.DateActive,
                Date_created          = pRetailAccount.DateCreated,
                Date_expired          = pRetailAccount.DateExpired,
                Date_to_expire        = pRetailAccount.DateToExpire,
                Retail_acct_id        = pRetailAccount.RetailAcctId,
                Start_balance         = pRetailAccount.StartBalance,
                Start_bonus_minutes   = pRetailAccount.StartBonusMinutes
            };

            if (pRetailAccount.CustomerAcctId > 0)
            {
                _retailAccountRow.Customer_acct_id = pRetailAccount.CustomerAcctId;
            }

            return(_retailAccountRow);
        }
        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();
                }
            }
        }
Пример #9
0
 public void UpdateAcct(Rbr_Db pDb, RetailAccountDto pRetailAcct)
 {
     Update(pDb, MapToRetailAccountRow(pRetailAcct));
 }
Пример #10
0
 internal void Delete(Rbr_Db pDb, RetailAccountDto pRetailAccount)
 {
     pDb.RetailAccountCollection.DeleteByPrimaryKey(pRetailAccount.RetailAcctId);
 }