public HttpResponseMessage ActivateGatewayProvider(GatewayProviderDisplay gatewayProvider)
        {
            var response = Request.CreateResponse(HttpStatusCode.OK);

            try
            {
                var gatewayProviderType = EnumTypeFieldConverter.GatewayProvider.GetTypeField(gatewayProvider.ProviderTfKey);

                var provider = GetGatewayProviderFromResolver(gatewayProvider, gatewayProviderType);

                if (provider == null || provider.Activated)
                {
                    return Request.CreateResponse(HttpStatusCode.NotFound, String.Format("{0}", "Provider could not be found or has already been activated"));
                }

                ToggleProviderActivation(provider, gatewayProviderType);

            }
            catch (Exception ex)
            {
                response = Request.CreateResponse(HttpStatusCode.InternalServerError, String.Format("{0}", ex.Message));
            }

            return response;
        }
        internal static IGatewayProviderSettings ToGatewayProvider(this GatewayProviderDisplay gatewayProvider, IGatewayProviderSettings destination)
        {
            if (gatewayProvider.Key != Guid.Empty)
            {
                destination.Key = gatewayProvider.Key;
            }
            // type key and typeFullName should be handled by the resolver
            destination.Name                = gatewayProvider.Name;
            destination.Description         = gatewayProvider.Description;
            destination.EncryptExtendedData = gatewayProvider.EncryptExtendedData;

            ((GatewayProviderSettings)destination).ExtendedData = gatewayProvider.ExtendedData.AsExtendedDataCollection();

            return(destination);
        }
        /// <summary>
        /// Helper method to get get the <see cref="IGatewayProvider"/> from the appropriate resolver
        /// </summary>
        /// <param name="gatewayProvider">The <see cref="GatewayProviderDisplay"/></param>
        /// <param name="gatewayProviderType"></param>
        /// <returns>A <see cref="IGatewayProvider"/> or null</returns>
        // TODO refactor this
        private IGatewayProvider GetGatewayProviderFromResolver(GatewayProviderDisplay gatewayProvider, GatewayProviderType gatewayProviderType)
        {
            // get the type of the provider

            IGatewayProvider provider = null;

            switch (gatewayProviderType)
            {
                case GatewayProviderType.Payment:
                    provider = _gatewayContext.Payment.GetAllProviders().FirstOrDefault(x => x.Key == gatewayProvider.Key);
                    break;

                case GatewayProviderType.Shipping:
                    provider = _gatewayContext.Shipping.GetAllProviders().FirstOrDefault(x => x.Key == gatewayProvider.Key);
                    break;

                case GatewayProviderType.Taxation:
                    provider = _gatewayContext.Taxation.GetAllProviders().FirstOrDefault(x => x.Key == gatewayProvider.Key);
                    break;
            }

            return provider;
        }
        public HttpResponseMessage PutGatewayProvider(GatewayProviderDisplay gatewayProviderDisplay)
        {
            var response = Request.CreateResponse(HttpStatusCode.OK);

            try
            {
                var provider = _gatewayProviderService.GetGatewayProviderByKey(gatewayProviderDisplay.Key);
                _gatewayProviderService.Save(gatewayProviderDisplay.ToGatewayProvider(provider));

            }
            catch (Exception ex)
            {
                response = Request.CreateResponse(HttpStatusCode.NotFound, String.Format("{0}", ex.Message));
            }

            return response;
        }
        /// <summary>
        /// Helper method to get get the <see cref="IGatewayProviderSettings"/> from the appropriate resolver
        /// </summary>
        /// <param name="gatewayProvider">The <see cref="GatewayProviderDisplay"/></param>
        /// <param name="gatewayProviderType"></param>
        /// <returns>A <see cref="IGatewayProviderSettings"/> or null</returns>
        private IGatewayProviderSettings GetGatewayProviderFromResolver(GatewayProviderDisplay gatewayProvider, GatewayProviderType gatewayProviderType)
        {
            // get the type of the provider

            GatewayProviderBase provider = null;

            switch (gatewayProviderType)
            {
                case GatewayProviderType.Payment:
                    provider = _gatewayContext.Payment.GetProviderByKey(gatewayProvider.Key, false);
                    break;

                case GatewayProviderType.Shipping:
                    provider = _gatewayContext.Shipping.GetProviderByKey(gatewayProvider.Key, false);
                    break;

                case GatewayProviderType.Taxation:
                    provider = _gatewayContext.Taxation.GetProviderByKey(gatewayProvider.Key, false);
                    break;
            }

            return provider != null ? provider.GatewayProviderSettings : null;
        }