Пример #1
0
        public ActionResult Index() {
            var model = new MetadataIndexViewModel {
                TypeDefinitions = _contentDefinitionManager.ListTypeDefinitions(),
                PartDefinitions = _contentDefinitionManager.ListPartDefinitions()
            };
            var types = new XElement("Types");
            foreach (var type in model.TypeDefinitions) {
                types.Add(_contentDefinitionWriter.Export(type));
            }

            var parts = new XElement("Parts");
            foreach (var part in model.PartDefinitions) {
                parts.Add(_contentDefinitionWriter.Export(part));
            }

            var stringWriter = new StringWriter();
            using (var xmlWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings { Indent = true, IndentChars = "  " })) {
                if (xmlWriter != null) {
                    new XElement("Orchard", types, parts).WriteTo(xmlWriter);
                }
            }
            model.ExportText = stringWriter.ToString();

            return View(model);
        }
Пример #2
0
 public ActionResult Index(MetadataIndexViewModel model) {
     var root = XElement.Parse(model.ExportText);
     foreach (var element in root.Elements("Types").Elements()) {
         var typeElement = element;
         var typeName = XmlConvert.DecodeName(element.Name.LocalName);
         _contentDefinitionManager.AlterTypeDefinition(typeName, alteration => _contentDefinitionReader.Merge(typeElement, alteration));
     }
     foreach (var element in root.Elements("Parts").Elements()) {
         var partElement = element;
         var partName = XmlConvert.DecodeName(element.Name.LocalName);
         _contentDefinitionManager.AlterPartDefinition(partName, alteration => _contentDefinitionReader.Merge(partElement, alteration));
     }
     return RedirectToAction("Index");
 }