public static Result Add(VirtualSwitchDto pVirtualSwitch)
        {
            var _result = new Result();

            using (var _db = new Rbr_Db()) {
                using (var _tx = new Transaction(_db, pVirtualSwitch)) {
                    try {
                        //1. REQUIRED set Contact Info
                        if (pVirtualSwitch.ContactInfo.ContactInfoId == 0)
                        {
                            ContactInfoManager.Add(_db, pVirtualSwitch.ContactInfo);
                        }

                        VirtualSwitchManager.Add(_db, pVirtualSwitch);
                        _tx.Commit();
                    }
                    catch (Exception _ex) {
                        if (pVirtualSwitch.ContactInfo != null)
                        {
                            pVirtualSwitch.ContactInfo.ContactInfoId = 0;
                        }
                        _result.Success      = false;
                        _result.ErrorMessage = _ex.Message;
                        TimokLogger.Instance.LogRbr(LogSeverity.Error, "VirtualSwitchController.Add", string.Format("Exception:\r\n{0}", _ex));
                    }
                }
            }
            return(_result);
        }
Esempio n. 2
0
        public static Result SafeSave(PersonDto pPerson, string pSalt)
        {
            var _result = new Result();

            using (var _db = new Rbr_Db()) {
                using (var _tx = new Transaction(_db, pPerson, pSalt)) {
                    try {
                        if (pPerson.AccessScope == AccessScope.Switch && pPerson.VirtualSwitchId != AppConstants.DefaultVirtualSwitchId)
                        {
                            throw new Exception("Invalid state, DefaultVirtualSwitch not set");
                        }
                        if (pPerson.AccessScope == AccessScope.VirtualSwitch && pPerson.VirtualSwitchId <= 0)
                        {
                            throw new Exception("Invalid state, VirtualSwitch not set");
                        }
                        if (pPerson.AccessScope == AccessScope.Partner && pPerson.PartnerId == 0)
                        {
                            throw new Exception("Invalid state, Partner not set");
                        }
                        if (pPerson.AccessScope == AccessScope.ResellAgent && pPerson.PartnerId == 0)
                        {
                            throw new Exception("Invalid state, Partner not set");
                        }
                        if (pPerson.AccessScope == AccessScope.CustomerSupport && pPerson.GroupId == 0)
                        {
                            throw new Exception("Invalid state, Group not set");
                        }
                        if (pPerson.AccessScope == AccessScope.Consumer && pPerson.RetailAcctId == 0)
                        {
                            throw new Exception("Invalid state, RetailAccount not set");
                        }
                        if (pPerson.AccessScope == AccessScope.None)
                        {
                            throw new Exception("Invalid state, AccessScope not set");
                        }

                        //1. REQUIRED set Contact Info
                        if (pPerson.ContactInfo != null)
                        {
                            ContactInfoManager.Add(_db, pPerson.ContactInfo);
                        }

                        PersonManager.Save(_db, pSalt, pPerson);
                        _tx.Commit();
                    }
                    catch (Exception _ex) {
                        //_db.RollbackTransaction();
                        _result.Success      = false;
                        _result.ErrorMessage = _ex.Message;
                        TimokLogger.Instance.LogRbr(LogSeverity.Error, "PersonController.SafeSave", string.Format("Exception:\r\n{0}", _ex));
                    }
                }
            }
            return(_result);
        }
Esempio n. 3
0
        //NOTE: Use Save() when calling directly, it will generate correct salt.
        //NOTE: Add and Update should be used only by Replication on the remote side, so that they don't regenerate salt again !!!
        public static void Add(string pSalt, PartnerDto pPartner)
        {
            using (Rbr_Db _db = new Rbr_Db()) {
                using (Transaction _tx = new Transaction(_db, pSalt, pPartner)) {
                    try {
                        if (pPartner.ContactInfo.ContactInfoId == 0)
                        {
                            ContactInfoManager.Add(_db, pPartner.ContactInfo);
                        }

                        if (pPartner.BillingSchedule != null)
                        {
                            ScheduleManager.Save(_db, pPartner.BillingSchedule);
                        }

                        PartnerManager.Add(_db, pPartner);

                        if (pPartner.Employees != null)
                        {
                            foreach (PersonDto _employee in pPartner.Employees)
                            {
                                _employee.PartnerId = pPartner.PartnerId;
                                PersonManager.Save(_db, pSalt, _employee);
                            }
                        }
                    }
                    catch (Exception _ex) {
                        TimokLogger.Instance.LogRbr(LogSeverity.Error, "PartnerController.add", string.Format("Exception:\r\n{0}", _ex));
                        if (pPartner.ContactInfo != null)
                        {
                            pPartner.ContactInfo.ContactInfoId = 0;
                        }
                        if (pPartner.Employees != null)
                        {
                            foreach (PersonDto _employee in pPartner.Employees)
                            {
                                _employee.PersonId = 0;
                            }
                        }
                        if (pPartner.BillingSchedule != null)
                        {
                            pPartner.BillingSchedule.ScheduleId = 0;
                        }
                        throw;
                    }
                    _tx.Commit();
                }
            }
        }
        public static void Save(CustomerSupportVendorDto pCustomerSupportVendor)
        {
            using (Rbr_Db _db = new Rbr_Db()) {
                using (Transaction _tx = new Transaction(_db, pCustomerSupportVendor)) {
                    //1. REQUIRED set Contact Info
                    if (pCustomerSupportVendor.ContactInfo.ContactInfoId == 0)
                    {
                        ContactInfoManager.Add(_db, pCustomerSupportVendor.ContactInfo);
                    }
                    else
                    {
                        ContactInfoManager.Update(_db, pCustomerSupportVendor.ContactInfo);
                    }

                    CustomerSupportManager.SaveCustomerSupportVendor(_db, pCustomerSupportVendor);
                    _tx.Commit();
                }
            }
        }