public SIPProvider UpdateSIPProvider(SIPProvider sipProvider)
        {
            Customer customer = AuthoriseRequest();

            if (customer.AdminId != Customer.TOPLEVEL_ADMIN_ID && sipProvider.Owner != customer.CustomerUsername)
            {
                throw new ApplicationException("You are not authorised to update the SIP Provider.");
            }

            string validationError = SIPProvider.ValidateAndClean(sipProvider);

            if (validationError != null)
            {
                logger.Warn("Validation error in UpdateSIPProvider for customer " + customer.CustomerUsername + ". " + validationError);
                throw new ApplicationException(validationError);
            }
            else
            {
                if (m_providerRegDisabled && sipProvider.RegisterEnabled)
                {
                    logger.Warn("A SIP provider for customer " + customer.CustomerUsername + " had registrations enabled on a disabled registrations service.");
                    throw new ApplicationException("SIP provider registrations are disabled on this system.");
                }
                else
                {
                    return(SIPProviderPersistor.Update(sipProvider));
                }
            }
        }
        public SIPProvider AddSIPProvider(SIPProvider sipProvider)
        {
            Customer customer = AuthoriseRequest();

            if (!customer.ServiceLevel.IsNullOrBlank() && customer.ServiceLevel.ToLower() == "free")
            {
                // Check the number of SIP Provider is within limits.
                if (GetSIPProvidersCount(null) >= 1)
                {
                    throw new ApplicationException("The SIP Provider cannot be added as your existing SIP Provider count has reached the allowed limit for your service level.");
                }
            }

            sipProvider.Owner = customer.CustomerUsername;

            string validationError = SIPProvider.ValidateAndClean(sipProvider);

            if (validationError != null)
            {
                logger.Warn("Validation error in AddSIPProvider for customer " + customer.CustomerUsername + ". " + validationError);
                throw new ApplicationException(validationError);
            }
            else
            {
                return(SIPProviderPersistor.Add(sipProvider));
            }
        }
        public SIPProvider AddSIPProvider(SIPProvider sipProvider)
        {
            Customer customer = AuthoriseRequest();

            sipProvider.Owner = customer.CustomerUsername;

            string validationError = SIPProvider.ValidateAndClean(sipProvider);

            if (validationError != null)
            {
                logger.Warn("Validation error in AddSIPProvider for customer " + customer.CustomerUsername + ". " + validationError);
                throw new ApplicationException(validationError);
            }
            else
            {
                return(SIPProviderPersistor.Add(sipProvider));
            }
        }
        public SIPProvider UpdateSIPProvider(SIPProvider sipProvider)
        {
            Customer customer = AuthoriseRequest();

            if (customer.AdminId != Customer.TOPLEVEL_ADMIN_ID && sipProvider.Owner != customer.CustomerUsername)
            {
                throw new ApplicationException("You are not authorised to update the SIP Provider.");
            }

            string validationError = SIPProvider.ValidateAndClean(sipProvider);

            if (validationError != null)
            {
                logger.Warn("Validation error in UpdateSIPProvider for customer " + customer.CustomerUsername + ". " + validationError);
                throw new ApplicationException(validationError);
            }
            else
            {
                return(SIPProviderPersistor.Update(sipProvider));
            }
        }