/// <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());
                    }
                }
            }
        }
Exemplo n.º 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,
                        savedEntity.ParentId,
                        propertyType.Alias,
                        propertyType.DataTypeDefinitionId,
                        propertyType.PropertyEditorAlias,
                        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.GetKeys(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());
                    }
                }
            }
        }
Exemplo n.º 3
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());
                    }
                }
            }
        }