/// <summary> /// Removes a custom field from the Press article /// </summary> /// <param name="fieldname">custom field name to be removed</param> public void RemoveCustomFieldFromContext(string fieldname) { Type pressArticleType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.PressRelease.PressArticle"); if (pressArticleType == null) { throw new ArgumentException("PressArticle type can't be resolved."); } var context = new CustomFieldsContext(pressArticleType); context.RemoveCustomFields(new string[] { fieldname }, pressArticleType.Name); context.SaveChanges(); SystemManager.RestartApplication(false); }
/// <summary> /// Removes a custom field from the Press article /// </summary> /// <param name="fieldname">custom field name to be removed</param> public void RemoveCustomFieldFromContext(string fieldname) { Type pressArticleType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.PressRelease.PressArticle"); if (pressArticleType == null) { throw new ArgumentException("PressArticle type can't be resolved."); } var context = new CustomFieldsContext(pressArticleType); context.RemoveCustomFields(new string[] { fieldname }, pressArticleType.Name); context.SaveChanges(); SystemManager.RestartApplication(false); }
/// <summary> /// Adds a custom field to Press article /// </summary> /// <param name="fieldname">Name of the field</param> /// <param name="isHierarchicalTaxonomy">is hierarchical taxonomy</param> public void AddCustomTaxonomyToContext(string fieldname, bool isHierarchicalTaxonomy) { Type pressArticleType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.PressRelease.PressArticle"); if (pressArticleType == null) { throw new ArgumentException("PressArticle type can't be resolved."); } var context = new CustomFieldsContext(pressArticleType); TaxonomyManager manager = TaxonomyManager.GetManager(); Guid taxonomyId; if (isHierarchicalTaxonomy == true) { var taxonomy = manager.GetTaxonomies<HierarchicalTaxonomy>().Where(t => t.Title == fieldname).SingleOrDefault(); if (taxonomy != null) { taxonomyId = taxonomy.Id; } else { throw new ArgumentException("The taxonomy '" + fieldname + "' does not exist in the system"); } } else { var taxonomy = manager.GetTaxonomies<FlatTaxonomy>().Where(t => t.Title == fieldname).SingleOrDefault(); if (taxonomy != null) { taxonomyId = taxonomy.Id; } else { throw new ArgumentException("The taxonomy '" + fieldname + "' does not exist in the system"); } } UserFriendlyDataType userFriendlyDataType = UserFriendlyDataType.Classification; var field = new WcfField() { Name = fieldname, ContentType = "Telerik.Sitefinity.DynamicTypes.Model.PressRelease.PressArticle", FieldTypeKey = userFriendlyDataType.ToString(), IsCustom = true, // Field definition Definition = new WcfFieldDefinition() { Title = fieldname, FieldName = fieldname.ToLower(), FieldType = isHierarchicalTaxonomy ? typeof(HierarchicalTaxonField).FullName : typeof(FlatTaxonField).FullName, TaxonomyId = taxonomyId.ToString(), AllowMultipleSelection = true, } }; var fields = new Dictionary<string, WcfField>(); fields.Add(field.FieldTypeKey, field); context.AddOrUpdateCustomFields(fields, pressArticleType.Name); context.SaveChanges(); }
/// <summary> /// Adds a custom field to Press article /// </summary> /// <param name="fieldname">Name of the field</param> /// <param name="isHierarchicalTaxonomy">is hierarchical taxonomy</param> public void AddCustomTaxonomyToContext(string fieldname, bool isHierarchicalTaxonomy) { Type pressArticleType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.PressRelease.PressArticle"); if (pressArticleType == null) { throw new ArgumentException("PressArticle type can't be resolved."); } var context = new CustomFieldsContext(pressArticleType); TaxonomyManager manager = TaxonomyManager.GetManager(); Guid taxonomyId; if (isHierarchicalTaxonomy == true) { var taxonomy = manager.GetTaxonomies <HierarchicalTaxonomy>().Where(t => t.Title == fieldname).SingleOrDefault(); if (taxonomy != null) { taxonomyId = taxonomy.Id; } else { throw new ArgumentException("The taxonomy '" + fieldname + "' does not exist in the system"); } } else { var taxonomy = manager.GetTaxonomies <FlatTaxonomy>().Where(t => t.Title == fieldname).SingleOrDefault(); if (taxonomy != null) { taxonomyId = taxonomy.Id; } else { throw new ArgumentException("The taxonomy '" + fieldname + "' does not exist in the system"); } } UserFriendlyDataType userFriendlyDataType = UserFriendlyDataType.Classification; var field = new WcfField() { Name = fieldname, ContentType = "Telerik.Sitefinity.DynamicTypes.Model.PressRelease.PressArticle", FieldTypeKey = userFriendlyDataType.ToString(), IsCustom = true, // Field definition Definition = new WcfFieldDefinition() { Title = fieldname, FieldName = fieldname.ToLower(), FieldType = isHierarchicalTaxonomy ? typeof(HierarchicalTaxonField).FullName : typeof(FlatTaxonField).FullName, TaxonomyId = taxonomyId.ToString(), AllowMultipleSelection = true, } }; var fields = new Dictionary <string, WcfField>(); fields.Add(field.FieldTypeKey, field); context.AddOrUpdateCustomFields(fields, pressArticleType.Name); context.SaveChanges(); }