public IHttpActionResult CreatePricelistAssignment(webModel.PricelistAssignment assignment)
        {
            var priceListAssignment = _pricingService.CreatePriceListAssignment(assignment.ToCoreModel());
            var result = priceListAssignment.ToWebModel(null, _extensionManager.ConditionExpressionTree);

            return(Ok(result));
        }
 public IHttpActionResult GetNewPricelistAssignments()
 {
     var result = new webModel.PricelistAssignment
     {
         Priority = 1,
         DynamicExpression = _extensionManager.ConditionExpressionTree
     };
     return Ok(result);
 }
        public IHttpActionResult GetNewPricelistAssignments()
        {
            var result = new webModel.PricelistAssignment
            {
                Priority          = 1,
                DynamicExpression = _extensionManager.ConditionExpressionTree
            };

            return(Ok(result));
        }
예제 #4
0
        public static coreModel.PricelistAssignment ToCoreModel(this webModel.PricelistAssignment assignment)
        {
            var retVal = new coreModel.PricelistAssignment();

            retVal.InjectFrom(assignment);

            var conditionExpression = assignment.DynamicExpression.GetConditionExpression();

            retVal.ConditionExpression = SerializationUtil.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;
            }
            retVal.PredicateVisualTreeSerialized = JsonConvert.SerializeObject(assignment.DynamicExpression);

            return(retVal);
        }
예제 #5
0
        public static webModel.PricelistAssignment ToWebModel(this coreModel.PricelistAssignment assignment, coreCatalogModel.Catalog[] catalogs = null, ConditionExpressionTree etalonEpressionTree = null)
        {
            var retVal = new webModel.PricelistAssignment();

            retVal.InjectFrom(assignment);

            if (catalogs != null)
            {
                var catalog = catalogs.FirstOrDefault(x => x.Id == assignment.CatalogId);
                if (catalog != null)
                {
                    retVal.CatalogName = catalog.Name;
                }
            }

            retVal.DynamicExpression = etalonEpressionTree;
            if (!String.IsNullOrEmpty(assignment.PredicateVisualTreeSerialized))
            {
                retVal.DynamicExpression = JsonConvert.DeserializeObject <ConditionExpressionTree>(assignment.PredicateVisualTreeSerialized);
                if (etalonEpressionTree != null)
                {
                    //Copy available elements from etalon because they not persisted
                    var sourceBlocks = ((DynamicExpression)etalonEpressionTree).Traverse(x => x.Children);
                    var targetBlocks = ((DynamicExpression)retVal.DynamicExpression).Traverse(x => x.Children);
                    foreach (var sourceBlock in sourceBlocks)
                    {
                        foreach (var targetBlock in targetBlocks.Where(x => x.Id == sourceBlock.Id))
                        {
                            targetBlock.AvailableChildren = sourceBlock.AvailableChildren;
                        }
                    }
                    //copy available elements from etalon
                    retVal.DynamicExpression.AvailableChildren = etalonEpressionTree.AvailableChildren;
                }
            }
            return(retVal);
        }
		public static webModel.PricelistAssignment ToWebModel(this coreModel.PricelistAssignment assignment, coreCatalogModel.Catalog[] catalogs = null, ConditionExpressionTree etalonEpressionTree = null)
		{
			var retVal = new webModel.PricelistAssignment();
			retVal.InjectFrom(assignment);
		
			if(catalogs != null)
			{
				var catalog = catalogs.FirstOrDefault(x => x.Id == assignment.CatalogId);
				if(catalog != null)
				{
					retVal.CatalogName = catalog.Name;
				}
			}

			retVal.DynamicExpression = etalonEpressionTree;
			if (!String.IsNullOrEmpty(assignment.PredicateVisualTreeSerialized))
			{
				retVal.DynamicExpression = JsonConvert.DeserializeObject<ConditionExpressionTree>(assignment.PredicateVisualTreeSerialized);
				if (etalonEpressionTree != null)
				{
					//Copy available elements from etalon because they not persisted
					var sourceBlocks = ((DynamicExpression)etalonEpressionTree).Traverse(x => x.Children);
					var targetBlocks = ((DynamicExpression)retVal.DynamicExpression).Traverse(x => x.Children);
					foreach (var sourceBlock in sourceBlocks)
					{
						foreach (var targetBlock in targetBlocks.Where(x => x.Id == sourceBlock.Id))
						{
							targetBlock.AvailableChildren = sourceBlock.AvailableChildren;
						}
					}
					//copy available elements from etalon
					retVal.DynamicExpression.AvailableChildren = etalonEpressionTree.AvailableChildren;
				}
			}
			return retVal;
		}
 public IHttpActionResult UpdatePriceListAssignment(webModel.PricelistAssignment assignment)
 {
     _pricingService.UpdatePricelistAssignments(new [] { assignment.ToCoreModel() });
     return(StatusCode(HttpStatusCode.NoContent));
 }