예제 #1
0
        public FindCustomersResponse Find(FindCustomersRequest request)
        {
            try
            {
                _customerQuery.Init();
                _customerQuery.WithOnlyActivated(true);
                _customerQuery.WithName(request.Name);
                _customerQuery.WithLastName(request.LastName);
                _customerQuery.WithGender(request.GenderType.ConvertToEnum <EGenderType>());
                _customerQuery.WithColony(request.Colony);
                _customerQuery.WithMunicipality(request.Municipality);
                _customerQuery.WithHomePhone(request.HomePhone);
                _customerQuery.WithCellPhone(request.CellPhone);
                _customerQuery.Sort(request.Sort, request.SortBy);
                var totalRecords = _customerQuery.TotalRecords();
                _customerQuery.Paginate(request.ItemsToShow, request.Page);
                var customers = _customerQuery.Execute();

                return(new FindCustomersResponse
                {
                    Customers = TypeAdapter.Adapt <List <CustomerResponse> >(customers),
                    TotalRecords = totalRecords
                });
            }
            catch (DataAccessException)
            {
                throw new ApplicationException();
            }
        }
예제 #2
0
        /// <summary>
        /// Search  Customers by email
        /// </summary>
        /// <param name="getCustomerByEmailParam">The Repository call params <see cref="GetCustomerByEmailParam"/></param>
        /// <returns>
        /// The Customer matching the requested Email, or null
        /// </returns>
        public virtual Task <CustomerQueryResult> GetCustomerByEmailAsync(GetCustomerByEmailParam getCustomerByEmailParam)
        {
            if (getCustomerByEmailParam == null)
            {
                throw new ArgumentNullException(nameof(getCustomerByEmailParam));
            }
            if (getCustomerByEmailParam.CultureInfo == null)
            {
                throw new ArgumentException(nameof(getCustomerByEmailParam.CultureInfo));
            }
            if (string.IsNullOrWhiteSpace(getCustomerByEmailParam.Scope))
            {
                throw new ArgumentException(nameof(getCustomerByEmailParam.Scope));
            }
            if (string.IsNullOrWhiteSpace(getCustomerByEmailParam.Email))
            {
                throw new ArgumentException(nameof(getCustomerByEmailParam.Email));
            }

            var cacheKey = new CacheKey(CacheConfigurationCategoryNames.Customer + "Search")
            {
                Scope       = getCustomerByEmailParam.Scope,
                CultureInfo = getCustomerByEmailParam.CultureInfo,
            };

            cacheKey.AppendKeyParts(getCustomerByEmailParam.Email);

            var request = new FindCustomersRequest
            {
                SearchTerms     = getCustomerByEmailParam.Email,
                FilteringScopes = getCustomerByEmailParam.Scope,
                ScopeId         = getCustomerByEmailParam.Scope,
                Query           = new Query
                {
                    IncludeTotalCount = true,
                    Sortings          = new List <QuerySorting>
                    {
                        new QuerySorting {
                            PropertyName = "AccountStatus", Direction = SortDirection.Ascending
                        },
                        new QuerySorting {
                            PropertyName = "LastActivityDate", Direction = SortDirection.Descending
                        }
                    }
                }
            };

            return(CacheProvider.GetOrAddAsync(cacheKey, () => OvertureClient.SendAsync(request)));
        }
예제 #3
0
        public override int GetNumberOfUsersOnline()
        {
            var onlineSpan  = new TimeSpan(0, System.Web.Security.Membership.UserIsOnlineTimeWindow, 0);
            var compareTime = DateTime.Now.Subtract(onlineSpan);

            var currentScope = GetCurrentScope();
            var request      = new FindCustomersRequest
            {
                SearchTerms     = null,
                FilteringScopes = currentScope,
                ScopeId         = currentScope,
                Query           = new Query
                {
                    IncludeTotalCount = true,
                    Filter            = new FilterGroup
                    {
                        Filters = new List <Filter>
                        {
                            new Filter {
                                Operator = Operator.GreaterThan, Member = "LastActivityDate", Value = compareTime
                            }
                        }
                    }
                }
            };

            try
            {
                var result = _client.Send(request);

                return(result.TotalCount);
            }
            catch (WebException ex)
            {
                throw new ProviderException(ex.Message, ex);
            }
            catch (WebServiceException ex)
            {
                throw new ProviderException(ex.ErrorMessage, ex);
            }
        }
예제 #4
0
        public override string GetUserNameByEmail(string email)
        {
            var currentScope = GetCurrentScope();
            var request      = new FindCustomersRequest
            {
                SearchTerms     = email,
                FilteringScopes = currentScope,
                ScopeId         = currentScope,
                Query           = new Query
                {
                    IncludeTotalCount = true,
                    Sortings          = new List <QuerySorting>
                    {
                        new QuerySorting {
                            PropertyName = "AccountStatus", Direction = SortDirection.Ascending
                        },
                        new QuerySorting {
                            PropertyName = "LastActivityDate", Direction = SortDirection.Descending
                        }
                    }
                }
            };

            try
            {
                var result = _client.Send(request);

                return(result.TotalCount == 0
                    ? null
                    : result.Results.First().Username);
            }
            catch (WebException ex)
            {
                throw new ProviderException(ex.Message, ex);
            }
            catch (WebServiceException ex)
            {
                throw new ProviderException(ex.ErrorMessage, ex);
            }
        }
예제 #5
0
        public override MembershipUserCollection FindUsersByEmail(string emailToMatch, int pageIndex, int pageSize,
                                                                  out int totalRecords)
        {
            var currentScope = GetCurrentScope();
            var request      = new FindCustomersRequest
            {
                SearchTerms     = emailToMatch,
                FilteringScopes = currentScope,
                ScopeId         = currentScope,
                Query           = new Query
                {
                    IncludeTotalCount = true,
                    StartingIndex     = pageIndex,
                    MaximumItems      = pageSize
                }
            };

            try
            {
                var membershipUsers = new MembershipUserCollection();
                var result          = _client.Send(request);

                totalRecords = result.TotalCount;

                result.Results.Select(ConvertToMembershipUser)
                .ToList().ForEach(membershipUsers.Add);

                return(membershipUsers);
            }
            catch (WebException ex)
            {
                throw new ProviderException(ex.Message, ex);
            }
            catch (WebServiceException ex)
            {
                throw new ProviderException(ex.ErrorMessage, ex);
            }
        }
예제 #6
0
 public FindCustomersResponse Get(FindCustomersRequest request)
 {
     return(_customerService.Find(request));
 }