protected List <KeyValueDTO> MapRoleControlsToFields()
        {
            var resultCollection = new List <KeyValueDTO>();

            //get existing userDefinedFields
            var usedDefinedFields = Storage.CrateContentsOfType <KeyValueListCM>(x => x.Label == "DocuSignTemplateUserDefinedFields").FirstOrDefault();

            if (usedDefinedFields != null)
            {
                var tempFieldCollection = usedDefinedFields.Values;

                var mappingBehavior  = new TextSourceMappingBehavior(Storage, "RolesMapping", true);
                var textSourceValues = mappingBehavior.GetValues(Payload);
                foreach (var item in textSourceValues)
                {
                    var field = tempFieldCollection.FirstOrDefault(x => x.Key == item.Key);
                    if (field != null)
                    {
                        //field.Tags = "RecepientId:" + item.Value;
                        field.Value = item.Value;
                        resultCollection.Add(field);
                    }
                }
            }
            return(resultCollection);
        }
        protected List <KeyValueDTO> MapControlsToFields()
        {
            //todo: refactor the method
            var resultCollection = new List <KeyValueDTO>();

            //get existing userDefinedFields
            var usedDefinedFields = Storage.CrateContentsOfType <KeyValueListCM>(x => x.Label == "DocuSignTemplateUserDefinedFields").FirstOrDefault();

            if (usedDefinedFields != null)
            {
                var tempFieldCollection = usedDefinedFields.Values;

                //extract data from text source Controls
                var mappingBehavior  = new TextSourceMappingBehavior(Storage, "Mapping", true);
                var textSourceValues = mappingBehavior.GetValues(Payload);
                foreach (var item in textSourceValues)
                {
                    var field = tempFieldCollection.FirstOrDefault(x => x.Key == item.Key);
                    if (field != null)
                    {
                        field.Value = item.Value;
                        resultCollection.Add(field);
                    }
                }

                var radiopGroupMappingBehavior = new RadioButtonGroupMappingBehavior(Storage, "RadioGroupMapping");
                var radioButtonGroups          = radiopGroupMappingBehavior.GetValues(Payload);
                foreach (var item in radioButtonGroups)
                {
                    var field = tempFieldCollection.FirstOrDefault(x => x.Key == item.GroupName);
                    if (field != null)
                    {
                        //get index of selected value
                        var selectedItem = item.Radios.FirstOrDefault(x => x.Selected);
                        if (selectedItem != null)
                        {
                            field.Value = selectedItem.Value.ToString();
                            resultCollection.Add(field);
                        }
                    }
                }

                var checkBoxMappingBehavior = new CheckBoxMappingBehavior(Storage, "CheckBoxMapping");
                var checkboxes = checkBoxMappingBehavior.GetValues(Payload);
                foreach (var item in checkboxes)
                {
                    var field = tempFieldCollection.FirstOrDefault(x => x.Key == item.Name);
                    if (field != null)
                    {
                        field.Value = item.Selected.ToString().ToLower();
                        resultCollection.Add(field);
                    }
                }

                var dropdownListMappingBehavior = new DropDownListMappingBehavior(Storage, "DropDownMapping");
                var dropDownLists = dropdownListMappingBehavior.GetValues();
                foreach (var item in dropDownLists)
                {
                    var field = tempFieldCollection.FirstOrDefault(x => x.Key == item.Name);
                    if (field != null)
                    {
                        field.Value = item.selectedKey;
                        resultCollection.Add(field);
                    }
                }
            }

            return(resultCollection);
        }