Example #1
0
        public override IEnumerable <TemplateViewModel> TypePartEditorUpdate(ContentTypePartDefinitionBuilder builder, IUpdateModel updateModel)
        {
            if (builder.Name != "CacheEvictorPart")
            {
                yield break;
            }
            var model = new CacheEvictorPartSettings();

            updateModel.TryUpdateModel(model, "CacheEvictorPartSettings", null, null);

            // validate the inserted id
            if (!string.IsNullOrEmpty(model.EvictItem))
            {
                int    id;
                string identityItems = string.Empty;
                foreach (var item in model.EvictItem.Split(';'))
                {
                    if (!string.IsNullOrWhiteSpace(item))
                    {
                        if (int.TryParse(item, out id))
                        {
                            var content = _contentManager.Get(id);
                            if (content != null)
                            {
                                var identity = _contentManager.GetItemMetadata(content).Identity;
                                if (identity != null)
                                {
                                    identityItems += identity.ToString() + ";";
                                }
                                else
                                {
                                    Services.Notifier.Error(T("CacheEvictorPart - The loaded id {0} does not exist", item));
                                }
                            }
                            else
                            {
                                Services.Notifier.Error(T("CacheEvictorPart - The loaded id {0} does not exist", item));
                            }
                        }
                        else
                        {
                            Services.Notifier.Error(T("CacheEvictorPart - {0} is not an id", item));
                        }
                    }
                }
                // if the validation was successful check the property the identity list
                model.IdentityEvictItem = identityItems;
            }

            // loads each settings field
            builder.WithSetting("CacheEvictorPartSettings.EvictItem", model.EvictItem);
            builder.WithSetting("CacheEvictorPartSettings.IdentityEvictItem", model.IdentityEvictItem);
        }
        public override IEnumerable <TemplateViewModel> TypePartEditorUpdate(ContentTypePartDefinitionBuilder builder, IUpdateModel updateModel)
        {
            if (builder.Name != "CacheEvictorPart")
            {
                yield break;
            }
            var model = new CacheEvictorPartSettings();

            model.QueryRecordEntries = GetQueriesRecordEntry();

            updateModel.TryUpdateModel(model, "CacheEvictorPartSettings", null, null);

            // get identity part of the ids for import/export
            var identityItems = string.Empty;

            if (!string.IsNullOrEmpty(model.EvictItem))
            {
                var ids = model.EvictItem.Split(';');
                // get identitypart
                if (ids.Any())
                {
                    int id;
                    foreach (var itemId in ids)
                    {
                        if (!string.IsNullOrWhiteSpace(itemId))
                        {
                            if (int.TryParse(itemId, out id))
                            {
                                identityItems += GetIdentityPart(id) + ";";
                            }
                            else
                            {
                                Services.Notifier.Error(T("CacheEvictorPart - {0} is not an id", itemId));
                            }
                        }
                    }
                }
            }
            model.IdentityEvictItem = identityItems;


            // managing the ids of selected queries
            model.FilterQueryRecordId = string.Join(";", model.FilterQueryRecordsId);
            if (!string.IsNullOrWhiteSpace(model.FilterQueryRecordId))
            {
                // get identitypart
                string identityQueryItems = string.Empty;

                if (model.FilterQueryRecordsId.Any())
                {
                    foreach (var itemId in model.FilterQueryRecordsId)
                    {
                        if (itemId == "-1")
                        {
                            identityQueryItems += itemId + ";";
                        }
                        else
                        {
                            identityQueryItems += GetIdentityPart(int.Parse(itemId)) + ";";
                        }
                    }
                }

                model.IdentityFilterQueryRecord = identityQueryItems;
            }

            // loads each settings field
            builder.WithSetting("CacheEvictorPartSettings.EvictItem", model.EvictItem);
            builder.WithSetting("CacheEvictorPartSettings.IdentityEvictItem", model.IdentityEvictItem);

            builder.WithSetting("CacheEvictorPartSettings.EvictTerms", model.EvictTerms.ToString());

            builder.WithSetting("CacheEvictorPartSettings.FilterQueryRecordId", model.FilterQueryRecordId);
            builder.WithSetting("CacheEvictorPartSettings.IdentityFilterQueryRecord", model.IdentityFilterQueryRecord);
        }