コード例 #1
0
        private void PopulateDynamicExpression(DynamicPromotion dynamicPromotion, JObject jObj)
        {
            var dynamicExpressionToken = jObj["dynamicExpression"];
            var dynamicExpression      = dynamicExpressionToken?.ToObject <PromoDynamicExpressionTree>();

            if (dynamicExpression?.Children != null)
            {
                var conditionExpression = dynamicExpression.GetConditionExpression();
                dynamicPromotion.PredicateSerialized = _expressionSerializer.SerializeExpression(conditionExpression);

                var rewards = dynamicExpression.GetRewards();
                dynamicPromotion.RewardsSerialized = JsonConvert.SerializeObject(rewards, new JsonSerializerSettings {
                    TypeNameHandling = TypeNameHandling.All
                });

                // Clear availableElements in expression to decrease size
                dynamicExpression.AvailableChildren = null;
                var allBlocks = ((DynamicExpression)dynamicExpression).Traverse(x => x.Children);
                foreach (var block in allBlocks)
                {
                    block.AvailableChildren = null;
                }

                dynamicPromotion.PredicateVisualTreeSerialized = JsonConvert.SerializeObject(dynamicExpression);
            }
        }
コード例 #2
0
        public static coreModel.DynamicContentPublication ToCoreModel(this webModel.DynamicContentPublication publication, IExpressionSerializer expressionSerializer)
        {
            var retVal = new coreModel.DynamicContentPublication();

            retVal.InjectFrom(publication);
            if (publication.ContentItems != null)
            {
                retVal.ContentItems = publication.ContentItems.Select(x => x.ToCoreModel()).ToList();
            }
            if (publication.ContentPlaces != null)
            {
                retVal.ContentPlaces = publication.ContentPlaces.Select(x => x.ToCoreModel()).ToList();
            }

            if (publication.DynamicExpression != null)
            {
                var conditionExpression = publication.DynamicExpression.GetConditionExpression();
                retVal.PredicateSerialized = expressionSerializer.SerializeExpression(conditionExpression);

                //Clear availableElements in expression (for decrease size)
                publication.DynamicExpression.AvailableChildren = null;
                var allBlocks = ((DynamicExpression)publication.DynamicExpression).Traverse(x => x.Children);
                foreach (var block in allBlocks)
                {
                    block.AvailableChildren = null;
                }
                retVal.PredicateVisualTreeSerialized = JsonConvert.SerializeObject(publication.DynamicExpression);
            }

            return(retVal);
        }
コード例 #3
0
        public static Promotion ToCoreModel(this webModel.Promotion promotion, IExpressionSerializer expressionSerializer)
        {
            var result = AbstractTypeFactory <DynamicPromotion> .TryCreateInstance();

            result.InjectFrom(promotion);

            //result.Coupons = promotion.Coupons;

            if (promotion.DynamicExpression?.Children != null)
            {
                var conditionExpression = promotion.DynamicExpression.GetConditionExpression();
                result.PredicateSerialized = expressionSerializer.SerializeExpression(conditionExpression);

                var rewards = promotion.DynamicExpression.GetRewards();
                result.RewardsSerialized = JsonConvert.SerializeObject(rewards, new JsonSerializerSettings {
                    TypeNameHandling = TypeNameHandling.All
                });

                // Clear availableElements in expression to decrease size
                promotion.DynamicExpression.AvailableChildren = null;
                var allBlocks = ((DynamicExpression)promotion.DynamicExpression).Traverse(x => x.Children);
                foreach (var block in allBlocks)
                {
                    block.AvailableChildren = null;
                }

                result.PredicateVisualTreeSerialized = JsonConvert.SerializeObject(promotion.DynamicExpression);
            }

            return(result);
        }
        private string GetPredicateSerialized(IConditionExpression[] conditions)
        {
            var predicate = PredicateBuilder.False <IEvaluationContext>();

            foreach (var expression in conditions.Select(x => x.GetConditionExpression()))
            {
                predicate = predicate.Or(expression);
            }

            return(expressionSerializer.SerializeExpression(predicate));
        }
コード例 #5
0
        public virtual void SavePricelistAssignments(coreModel.PricelistAssignment[] assignments)
        {
            var pkMap = new PrimaryKeyResolvingMap();

            using (var repository = _repositoryFactory())
                using (var changeTracker = GetChangeTracker(repository))
                {
                    var assignmentsIds       = assignments.Select(x => x.Id).Where(x => x != null).Distinct().ToArray();
                    var alreadyExistEntities = repository.GetPricelistAssignmentsById(assignmentsIds);
                    foreach (var assignment in assignments)
                    {
                        //Serialize condition expression
                        if (assignment.DynamicExpression != null && assignment.DynamicExpression.Children != null)
                        {
                            var conditionExpression = assignment.DynamicExpression.GetConditionExpression();
                            assignment.ConditionExpression = _expressionSerializer.SerializeExpression(conditionExpression);

                            //Clear availableElements in expression (for decrease size)
                            assignment.DynamicExpression.AvailableChildren = null;
                            var allBlocks = ((DynamicExpression)assignment.DynamicExpression).Traverse(x => x.Children);
                            foreach (var block in allBlocks)
                            {
                                block.AvailableChildren = null;
                            }
                            assignment.PredicateVisualTreeSerialized = JsonConvert.SerializeObject(assignment.DynamicExpression);
                        }

                        var sourceEntity = AbstractTypeFactory <dataModel.PricelistAssignmentEntity> .TryCreateInstance().FromModel(assignment, pkMap);

                        var targetEntity = alreadyExistEntities.FirstOrDefault(x => x.Id == assignment.Id);
                        if (targetEntity != null)
                        {
                            changeTracker.Attach(targetEntity);
                            sourceEntity.Patch(targetEntity);
                        }
                        else
                        {
                            repository.Add(sourceEntity);
                        }
                    }
                    CommitChanges(repository);
                    pkMap.ResolvePrimaryKeys();
                    ResetCache();
                }
        }