예제 #1
0
        /// <summary>
        /// Get a Picker model for the supplied propertyAlias on this <see cref="IPublishedContent"/>
        /// </summary>
        /// <param name="publishedContent">The IPublishedContent that this extension method extends</param>
        /// <param name="propertyAlias">The property alias to get the Picker for</param>
        /// <returns>A <see cref="Picker"/> or null</returns>
        public static Picker GetPicker(this IPublishedContent publishedContent, string propertyAlias)
        {
            var propertyType = publishedContent.ContentType.PropertyTypes.SingleOrDefault(x => x.PropertyTypeAlias == propertyAlias);

            if (propertyType != null)
            {
                if (PickerPropertyValueConverter.IsPicker(propertyType.PropertyEditorAlias))
                {
                    return(new Picker(publishedContent.Id, propertyAlias));
                }
            }

            return(null);
        }
예제 #2
0
        /// <summary>
        /// combined event for content / media / member
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="savedEntities"></param>
        private void Saved(IService sender, IEnumerable <IContentBase> savedEntities)
        {
            foreach (IContentBase savedEntity in savedEntities)
            {
                // for each property
                foreach (PropertyType propertyType in savedEntity.PropertyTypes.Where(x => PickerPropertyValueConverter.IsPicker(x.PropertyEditorAlias)))
                {
                    // create picker supplying all values
                    Picker picker = new Picker(savedEntity.Id,
                                               propertyType.Alias,
                                               propertyType.DataTypeDefinitionId,
                                               savedEntity.GetValue(propertyType.Alias));

                    if (!string.IsNullOrWhiteSpace(picker.RelationTypeAlias))
                    {
                        bool isRelationsOnly = picker.GetDataTypePreValue("saveFormat").Value == "relationsOnly";

                        if (isRelationsOnly)
                        {
                            if (picker.SavedValue == null)
                            {
                                picker.PickedKeys = new string[] { };
                            }
                            else
                            {
                                // manually set on picker obj, so it doesn't then attempt to read picked keys from the database
                                picker.PickedKeys = SaveFormat.GetSavedKeys(picker.SavedValue.ToString()).ToArray();

                                // delete saved value (setting it to null)
                                //savedEntity.SetValue(propertyType.Alias, null);

                                //if (sender is IContentService)
                                //{
                                //    ((IContentService)sender).Save((IContent)savedEntity, 0, false);
                                //}
                                //else if (sender is IMediaService)
                                //{
                                //    ((IMediaService)sender).Save((IMedia)savedEntity, 0, false);
                                //}
                                //else if (sender is IMemberService)
                                //{
                                //    ((IMemberService)sender).Save((IMember)savedEntity, false);
                                //}
                            }
                        }

                        // update database
                        RelationMapping.UpdateRelationMapping(
                            picker.ContextId,                               // savedEntity.Id
                            picker.PropertyAlias,                           // propertyType.Alias
                            picker.RelationTypeAlias,
                            isRelationsOnly,
                            picker.PickedIds.ToArray());
                    }
                }
            }
        }
        /// <summary>
        /// combined event for content / media / member
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="savedEntities"></param>
        private void Saved(IService sender, IEnumerable <IContentBase> savedEntities)
        {
            foreach (IContentBase savedEntity in savedEntities)
            {
                // for each property
                foreach (PropertyType propertyType in savedEntity.PropertyTypes.Where(x => PickerPropertyValueConverter.IsPicker(x.PropertyEditorAlias)))
                {
                    // create picker supplying all values
                    Picker picker = new Picker(savedEntity.Id,
                                               propertyType.Alias,
                                               propertyType.DataTypeDefinitionId,
                                               savedEntity.GetValue(propertyType.Alias));

                    if (!string.IsNullOrWhiteSpace(picker.RelationTypeAlias))
                    {
                        RelationMapping.UpdateRelationMapping(
                            picker.ContextId,                               // savedEntity.Id
                            picker.PropertyAlias,                           // propertyType.Alias
                            picker.RelationTypeAlias,
                            picker.GetDataTypePreValue("saveFormat").Value == "relationsOnly",
                            picker.PickedIds.ToArray());
                    }
                }
            }
        }