Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Chris Whittington 6 posts 26 karma points
    Aug 01, 2013 @ 16:44
    Chris Whittington
    0

    Prevalues in new API

    Hi, I have a requirement to update a prevalue in a datatypedefinition post install/content creation...

    Im currently using a DataSettingsEditorStorage class that lets me retrieve a list of settings: List<Setting<string,string>> (where the first string is the alias from the DB table [cmsDataTypePreValues] and the second string is the value).

    I am iterating over the list and (using the alias as a key) updating the correct value.

    Here is an example piece of code...

     var currentSettingsList = this.GetCurrentSettings(this.dataEditorSettingsStorageWrapper, dataTypeDefinitionWrapper.Id);
    
            // Container for the list of settings that will be pushed back to Umbraco
            var settingsToPushList = new List<Setting<string, string>>();
    
            // loop through existing settings, checking if they need to be overridden - if not add it back unchanged
            foreach (var currentSetting in currentSettingsList)
            {
                var settingToPush = currentSetting;
    
                var settingToUpdate = newDtdSettings.SettingsToUpdate.FirstOrDefault(x => x.Key == currentSetting.Key);
    
                if (settingToUpdate.Key != null)
                {
                    // make sure that a check for the node exists is performed - if required
                    if (newDtdSettings.SettingsRequiringNodeExistsCheck.Contains(currentSetting.Key) && !nodeHelper.NodeExists(int.Parse(settingToUpdate.Value)))
                    {
                        throw new ArgumentNullException(string.Format("Unable to resolve node: {0}", settingToUpdate.Value));
                    }
    
                    settingToPush.Value = settingToUpdate.Value;
                }
    
                settingsToPushList.Add(settingToPush);
            }
    
    public IEnumerable<Setting<string, string>> GetCurrentSettings(IDataEditorSettingsStorageWrapper settingsStorageWrapper, int dataTypeDefinitionNodeId)
        {
            var currentSettings = settingsStorageWrapper.GetSettings(dataTypeDefinitionNodeId);
    
            if (currentSettings == null)
            {
                throw new NullReferenceException();
            }
            return currentSettings;
        }
    

    This is being used in conjunction with a bunch of other methods that do not use the newer (V6) Services.

    I want to port my code over to use the newer services, but as I go, have noticed that the only options available on the IDataTypeService for retrieving prevalues are:

    //
        // Summary:
        //     Gets a specific PreValue by its Id
        //
        // Parameters:
        //   id:
        //     Id of the PreValue to retrieve the value from
        //
        // Returns:
        //     PreValue as a string
        string GetPreValueAsString(int id);
        //
        // Summary:
        //     Gets all values for an Umbraco.Core.Models.IDataTypeDefinition
        //
        // Parameters:
        //   id:
        //     Id of the Umbraco.Core.Models.IDataTypeDefinition to retrieve prevalues from
        //
        // Returns:
        //     An enumerable list of string values
        IEnumerable<string> GetPreValuesByDataTypeId(int id);
    

    As this list only contains values, I lose the ability to determine (via the alias) which item needs changing. Is there anyway to return - via the new Services - a list of prevalue settings (alias/value) or indeed a better way of doing all this??? I am hesitant to return an Ienumerable

    (hopefully i've explained that enough, if anymore detail is needed I am happy to explain further...)

    Cheers,

    Chris Whitts

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies