Example #1
0
        /// <summary>
        /// Gets a single Customer identifier by username
        /// </summary>
        /// <param name="getCustomerByUsernameParam">The Repository call params <see cref="GetCustomerByUsernameParam"/></param>
        /// <returns>
        /// The Customer matching the requested username, or null
        /// </returns>
        public virtual Task <Customer> GetCustomerByUsernameAsync(GetCustomerByUsernameParam getCustomerByUsernameParam)
        {
            if (getCustomerByUsernameParam == null)
            {
                throw new ArgumentNullException(nameof(getCustomerByUsernameParam));
            }
            if (getCustomerByUsernameParam.CultureInfo == null)
            {
                throw new ArgumentException(nameof(getCustomerByUsernameParam.CultureInfo));
            }
            if (string.IsNullOrWhiteSpace(getCustomerByUsernameParam.Scope))
            {
                throw new ArgumentException(nameof(getCustomerByUsernameParam.Scope));
            }
            if (string.IsNullOrWhiteSpace(getCustomerByUsernameParam.Username))
            {
                throw new ArgumentException(nameof(getCustomerByUsernameParam.Username));
            }

            var cacheKey = new CacheKey(CacheConfigurationCategoryNames.Customer)
            {
                Scope       = getCustomerByUsernameParam.Scope,
                CultureInfo = getCustomerByUsernameParam.CultureInfo,
            };

            cacheKey.AppendKeyParts(getCustomerByUsernameParam.Username);

            var getCustomerByUsernameRequest = new GetCustomerByUsernameRequest
            {
                IncludeAddresses = false,
                ScopeId          = getCustomerByUsernameParam.Scope,
                Username         = getCustomerByUsernameParam.Username,
            };

            return(CacheProvider.GetOrAddAsync(cacheKey, () => OvertureClient.SendAsync(getCustomerByUsernameRequest)));
        }
Example #2
0
        private Customer GetCustomerByUsername(string username)
        {
            if (username == null)
            {
                throw new ArgumentNullException("username");
            }

            try
            {
                var getRequest = new GetCustomerByUsernameRequest {
                    Username = username, ScopeId = GetCurrentScope()
                };

                return(_client.Send(getRequest));
            }
            catch (WebException ex)
            {
                throw new ProviderException(ex.Message, ex);
            }
            catch (WebServiceException ex)
            {
                throw new ProviderException(ex.ErrorMessage, ex);
            }
        }