public virtual DemoCustomerSegment ToModel(DemoCustomerSegment customerSegment)
        {
            if (customerSegment == null)
            {
                throw new ArgumentNullException(nameof(customerSegment));
            }

            customerSegment.Id           = Id;
            customerSegment.CreatedBy    = CreatedBy;
            customerSegment.CreatedDate  = CreatedDate;
            customerSegment.ModifiedBy   = ModifiedBy;
            customerSegment.ModifiedDate = ModifiedDate;

            customerSegment.Name        = Name;
            customerSegment.Description = Description;
            customerSegment.UserGroup   = UserGroup;
            customerSegment.IsActive    = IsActive;
            customerSegment.StartDate   = StartDate;
            customerSegment.EndDate     = EndDate;

            customerSegment.ExpressionTree = AbstractTypeFactory <DemoCustomerSegmentTree> .TryCreateInstance();

            if (ExpressionTreeSerialized != null)
            {
                customerSegment.ExpressionTree = JsonConvert.DeserializeObject <DemoCustomerSegmentTree>(ExpressionTreeSerialized, new DemoConditionJsonConverter());
            }

            if (Stores != null)
            {
                customerSegment.StoreIds = Stores.Select(x => x.StoreId).ToList();
            }

            return(customerSegment);
        }
        public static void ExpireEntity(DemoCustomerSegment customerSegment)
        {
            if (customerSegment == null)
            {
                throw new ArgumentNullException(nameof(customerSegment));
            }

            ExpireTokenForKey(customerSegment.Id);
        }
Exemplo n.º 3
0
        private async Task <IList <IndexDocument> > BuildIndexDocuments(DemoCustomerSegment segment, params Member[] customers)
        {
            var documentBuilder = new DemoMemberDocumentBuilder(
                GetMemberService(customers),
                GetDynamicPropertySearchService(),
                new UserGroupEvaluator(GetCustomerSegmentSearchService(segment)));

            return(await documentBuilder.GetDocumentsAsync(customers.Select(customer => customer.Id).ToList()));
        }
Exemplo n.º 4
0
        private DemoCustomerSegment CreateCustomerSegment(DynamicObjectProperty[] properties, string[] storeIds, string userGroup)
        {
            var segment = new DemoCustomerSegment
            {
                UserGroup = userGroup, StoreIds = storeIds, ExpressionTree = new DemoCustomerSegmentTree()
            };

            segment.ExpressionTree.MergeFromPrototype(new DemoCustomerSegmentTreePrototype());
            var block = segment.ExpressionTree.Children
                        .First(child => child.Id == nameof(DemoBlockCustomerSegmentRule));
            var condition = (DemoConditionPropertyValues)block.AvailableChildren
                            .First(child => child.Id == nameof(DemoConditionPropertyValues));

            block.Children.Add(condition);
            condition.Properties = properties;
            condition.StoreIds   = storeIds;

            return(segment);
        }
        public virtual DemoCustomerSegmentEntity FromModel(DemoCustomerSegment customerSegment, PrimaryKeyResolvingMap pkMap)
        {
            if (customerSegment == null)
            {
                throw new ArgumentNullException(nameof(customerSegment));
            }

            pkMap.AddPair(customerSegment, this);

            Id           = customerSegment.Id;
            CreatedBy    = customerSegment.CreatedBy;
            CreatedDate  = customerSegment.CreatedDate;
            ModifiedBy   = customerSegment.ModifiedBy;
            ModifiedDate = customerSegment.ModifiedDate;

            Name        = customerSegment.Name;
            Description = customerSegment.Description;
            UserGroup   = customerSegment.UserGroup;
            IsActive    = customerSegment.IsActive;
            StartDate   = customerSegment.StartDate;
            EndDate     = customerSegment.EndDate;

            if (customerSegment.ExpressionTree != null)
            {
                ExpressionTreeSerialized = JsonConvert.SerializeObject(customerSegment.ExpressionTree, new DemoConditionJsonConverter(doNotSerializeAvailCondition: true));
            }

            if (customerSegment.StoreIds != null)
            {
                Stores = new ObservableCollection <DemoCustomerSegmentStoreEntity>(customerSegment.StoreIds.Select(x => new DemoCustomerSegmentStoreEntity {
                    StoreId = x, CustomerSegmentId = customerSegment.Id
                }));
            }

            return(this);
        }