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); }
public static dataModel.DynamicContentPublishingGroup ToDataModel(this coreModel.DynamicContentPublication publication) { if (publication == null) { throw new ArgumentNullException("publication"); } var retVal = new dataModel.DynamicContentPublishingGroup(); retVal.InjectFrom(publication); retVal.ConditionExpression = publication.PredicateSerialized; retVal.PredicateVisualTreeSerialized = publication.PredicateVisualTreeSerialized; if (publication.ContentItems != null) { retVal.ContentItems = new ObservableCollection <dataModel.PublishingGroupContentItem>(publication.ContentItems.Select(x => new dataModel.PublishingGroupContentItem { DynamicContentPublishingGroupId = retVal.Id, DynamicContentItemId = x.Id })); } if (publication.ContentPlaces != null) { retVal.ContentPlaces = new ObservableCollection <dataModel.PublishingGroupContentPlace>(publication.ContentPlaces.Select(x => new dataModel.PublishingGroupContentPlace { DynamicContentPublishingGroupId = retVal.Id, DynamicContentPlaceId = x.Id })); } return(retVal); }
/// <summary> /// Converting to model type /// </summary> /// <param name="catalogBase"></param> /// <returns></returns> public static coreModel.DynamicContentPublication ToCoreModel(this dataModel.DynamicContentPublishingGroup dbEntity) { if (dbEntity == null) { throw new ArgumentNullException("dbEntity"); } var retVal = new coreModel.DynamicContentPublication(); retVal.InjectFrom(dbEntity); retVal.PredicateSerialized = dbEntity.ConditionExpression; retVal.PredicateVisualTreeSerialized = dbEntity.PredicateVisualTreeSerialized; if (dbEntity.ContentItems != null) { retVal.ContentItems = dbEntity.ContentItems.Select(x => x.ContentItem.ToCoreModel()).ToList(); } if (dbEntity.ContentPlaces != null) { retVal.ContentPlaces = dbEntity.ContentPlaces.Select(x => x.ContentPlace.ToCoreModel()).ToList(); } return(retVal); }
public static coreModel.DynamicContentPublication ToCoreModel(this webModel.DynamicContentPublication publication) { 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(); } var conditionExpression = publication.DynamicExpression.GetConditionExpression(); retVal.PredicateSerialized = SerializationUtil.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; }
public coreModel.DynamicContentPublication GetPublicationById(string id) { coreModel.DynamicContentPublication retVal = null; using (var repository = _repositoryFactory()) { var entity = repository.GetContentPublicationById(id); if (entity != null) { retVal = entity.ToCoreModel(); } } return(retVal); }
public coreModel.DynamicContentPublication CreatePublication(coreModel.DynamicContentPublication publication) { var entity = publication.ToDataModel(); coreModel.DynamicContentPublication retVal = null; using (var repository = _repositoryFactory()) { repository.Add(entity); CommitChanges(repository); } retVal = GetPublicationById(entity.Id); return(retVal); }
/// <summary> /// Converting to model type /// </summary> /// <param name="catalogBase"></param> /// <returns></returns> public static coreModel.DynamicContentPublication ToCoreModel(this dataModel.DynamicContentPublishingGroup dbEntity) { if (dbEntity == null) throw new ArgumentNullException("dbEntity"); var retVal = new coreModel.DynamicContentPublication(); retVal.InjectFrom(dbEntity); retVal.PredicateSerialized = dbEntity.ConditionExpression; retVal.PredicateVisualTreeSerialized = dbEntity.PredicateVisualTreeSerialized; if (dbEntity.ContentItems != null) { retVal.ContentItems = dbEntity.ContentItems.Select(x => x.ContentItem.ToCoreModel()).ToList(); } if (dbEntity.ContentPlaces != null) { retVal.ContentPlaces = dbEntity.ContentPlaces.Select(x => x.ContentPlace.ToCoreModel()).ToList(); } return retVal; }
public static webModel.DynamicContentPublication ToWebModel(this coreModel.DynamicContentPublication publication, ConditionExpressionTree etalonEpressionTree = null) { var retVal = new webModel.DynamicContentPublication(); retVal.InjectFrom(publication); if (publication.ContentItems != null) { retVal.ContentItems = publication.ContentItems.Select(x => x.ToWebModel()).ToList(); } if (publication.ContentPlaces != null) { retVal.ContentPlaces = publication.ContentPlaces.Select(x => x.ToWebModel()).ToList(); } retVal.DynamicExpression = etalonEpressionTree; if (!string.IsNullOrEmpty(publication.PredicateVisualTreeSerialized)) { retVal.DynamicExpression = JsonConvert.DeserializeObject <ConditionExpressionTree>(publication.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).ToList(); 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); }