コード例 #1
0
        public async Task <ICollection <UserGroupInfo> > EvaluateUserGroupsAsync(IEvaluationContext context)
        {
            var result = new List <UserGroupInfo>();

            if (context is UserGroupEvaluationContext evaluationContext)
            {
                var customerSegments =
                    (await _customerSegmentSearchService.SearchCustomerSegmentsAsync(new CustomerSegmentSearchCriteria {
                    IsActive = true
                })).Results;

                result = customerSegments
                         .Where(customerSegment => !customerSegment.UserGroup.IsNullOrEmpty() && customerSegment.ExpressionTree.IsSatisfiedBy(new CustomerSegmentExpressionEvaluationContext {
                    Customer = evaluationContext.Customer
                }))
                         .Select(customerSegment => new UserGroupInfo
                {
                    IsDynamic       = true,
                    DynamicRuleId   = customerSegment.Id,
                    DynamicRuleName = customerSegment.Name,
                    UserGroup       = customerSegment.UserGroup
                })
                         .ToList();

                var staticUserGroups = evaluationContext.Customer.Groups.Select(group => new UserGroupInfo
                {
                    UserGroup = group
                });

                result.AddRange(staticUserGroups);
            }

            return(result);
        }
        public async Task <ActionResult <CustomerSegmentSearchResult> > SearchCustomerSegments([FromBody] CustomerSegmentSearchCriteria criteria)
        {
            var result = await _customerSegmentSearchService.SearchCustomerSegmentsAsync(criteria);

            return(Ok(result));
        }