public static BrandMetadataSetting RenameMetadataFieldName(int brandMetadataSettingId, string fieldName) { fieldName = fieldName.Trim(); if (StringUtils.IsBlank(fieldName)) { throw new SystemException("Field name cannot be empty"); } BrandMetadataSetting setting = BrandMetadataSetting.Get(brandMetadataSettingId); if (setting.IsNull) { throw new SystemException("Metadata setting not found"); } BrandMetadataSettingFinder finder = new BrandMetadataSettingFinder { BrandId = setting.BrandId, FieldName = fieldName }; int count = BrandMetadataSetting.GetCount(finder); if (count > 0) { throw new SystemException(string.Format("Another metadata setting with the name '{0}' already exists in this brand", fieldName)); } setting.FieldName = fieldName; BrandMetadataSetting.Update(setting); CacheManager.InvalidateCache("Brand", CacheType.All); return(setting); }
/// <summary> /// deletes the setting, all stored possible selection values and all selected values for all assets /// </summary> /// <param name="brandMetadataSettingId">the setting to be deleted</param> public static void DeleteSettingAndValues(int brandMetadataSettingId) { var setting = BrandMetadataSetting.Get(brandMetadataSettingId); if (setting == null) { return; } var group = setting.GroupNumber; var metaValuesFinder = new MetadataFinder() { GroupNumber = group }; var vals = Metadata.FindMany(metaValuesFinder); var assetMetaFinder = new AssetMetadataFinder() { }; //iterate through all values, delete existing assetmetadata selection and then delete values themselves as well foreach (var metaValue in vals) { assetMetaFinder.MetadataId = metaValue.MetadataId.GetValueOrDefault(); var assetMetaSelections = AssetMetadata.FindMany(assetMetaFinder); foreach (var assetMeta in assetMetaSelections) { AssetMetadata.Delete(assetMeta.AssetMetadataId); } Metadata.Delete(metaValue.MetadataId); } //delete selectable setting if one exists if (!setting.SelectableSetting.IsNull && !setting.SelectableSetting.IsNew) { BrandMetadataSelectableSetting.Delete(setting.SelectableSetting.BrandMetadataSelectableSettingId); } //delete the setting itself BrandMetadataSetting.Delete(brandMetadataSettingId); }