Exemple #1
0
        // This method saves the content in accordance with the save action selected by the user for the item.
        private SaveAction SaveContent(IContent content, IGcItem item, GcDynamicTemplateMappings currentMapping)
        {
            /*
             *  <summary>
             *      Select the status/SaveAction from the mapping where first part of the 'MappedEpiServerStatus'
             *      matches the current Gc status ID. If the 'MappedEpiServerStatus' is set to 'Use Default Status',
             *      then fetch the SaveAction that matches the 'DefaultStatus' string from the mapping and select it.
             *      Else, fetch the SaveAction that matches the 'statusFromMapping' string and select it.
             *  </summary>
             */
            var        gcStatusIdForThisItem = item.CurrentStatus.Data.Id;
            SaveAction saveAction;

            var statusFromMapping = currentMapping.StatusMaps
                                    .Find(i => i.MappedEpiserverStatus.Split('~')[1] == gcStatusIdForThisItem)
                                    .MappedEpiserverStatus.Split('~')[0];

            if (statusFromMapping == "Use Default Status")
            {
                saveAction = _saveActions.Find(i => i.ToString() == currentMapping.DefaultStatus);
                _contentRepository.Save(content, saveAction, AccessLevel.Administer);
            }

            else
            {
                saveAction = _saveActions.Find(i => i.ToString() == statusFromMapping);
                _contentRepository.Save(content, saveAction, AccessLevel.Administer);
            }

            return(saveAction);
        }
Exemple #2
0
        private List <GcFile> MapValuesFromGcToEpi(IContentData content, ContentType contentType, GcDynamicTemplateMappings currentMapping,
                                                   IGcItem gcItem)
        {
            // fetch all the GcFile collection for this item.
            var gcFiles = Client.GetFilesByItemId(gcItem.Id).ToList();

            // This list contains the fields of the attachments for which the media has to be imported.
            var mediaFieldsToImport = new List <string>();

            // Get all the configs of this item.
            var gcConfigs = gcItem.Config.ToList();

            foreach (var map in currentMapping.EpiFieldMaps)
            {
                // First part of the string contains Epi field name and second part contains the Gc field name.
                var fieldSplitStrings = map.Split('~');
                var epiFieldName      = fieldSplitStrings[0];
                var gcFieldName       = fieldSplitStrings[1];

                // Add the fields to 'mediaFieldsToImport' list whose Epi counter part is 'Import-Attachments'.
                if (!gcFiles.IsNullOrEmpty())
                {
                    if (gcFiles.Any(i => i.Field == gcFieldName && epiFieldName == "Import-Attachments"))
                    {
                        mediaFieldsToImport.Add(gcFieldName);
                    }
                }

                /*
                 *  <summary>
                 *      For the field name that matches the field name of Epi content type, find the GcElement whose name is
                 *      the extracted gcFieldName. Call a parser based on the GcElement type. (Files gets imported differently.)
                 *  </summary>
                 */
                var propDef = contentType.PropertyDefinitions.ToList().Find(p => p.Name == epiFieldName);
                if (propDef == null)
                {
                    continue;
                }
                foreach (var gcConfig in gcConfigs)
                {
                    foreach (var gcElement in gcConfig.Elements.ToList())
                    {
                        if (gcElement.Name != gcFieldName)
                        {
                            continue;
                        }
                        if (gcElement.Type == "text")
                        {
                            content.Property[propDef.Name].Value =
                                GcEpiContentParser.TextParser(gcElement.Value, propDef.Type.Name);
                        }
                        else if (gcElement.Type == "section")
                        {
                            content.Property[propDef.Name].Value =
                                GcEpiContentParser.TextParser(gcElement.Subtitle, propDef.Type.Name);
                        }

                        /*else if (gcElement.Type == "choice_radio" || gcElement.Type == "choice_checkbox")
                         *  content.Property[propDef.Name].Value =
                         *      GcEpiContentParser.ChoiceParser(gcElement.Options, gcElement.Type, propDef);*/
                    }
                }
            }

            // Return all the files if the selected value of that
            // field is 'Import-Attachments' and is in 'mediaFieldsToImport' list.
            return(gcFiles.Where(i => mediaFieldsToImport.Contains(i.Field)).ToList());
        }