コード例 #1
0
        public async Task <IActionResult> EditDynamic([FromQuery] string url)
        {
            if (string.IsNullOrEmpty(url))
            {
                return(new NotFoundResult());
            }

            var httpClient = httpClientFactory.CreateClient();
            var json       = await httpClient.GetStringAsync(url).ConfigureAwait(false);

            var jsonSchema = JsonSchema.FromSampleJson(json);

            var schema = new SchemaLocation()
            {
                Key    = "_dynamic",
                Schema = jsonSchema.ToJson()
            };

            var model = new EditViewModel
            {
                CmsType          = "_dynamic",
                Id               = Guid.NewGuid(),
                SchemaLocation   = schema,
                CmsConfiguration = schemaService.GetCmsConfiguration(),
                Data             = JsonSerializer.Deserialize <CmsItem>(json)
            };

            return(View(nameof(Edit), model));
        }
コード例 #2
0
        public async Task ClearData()
        {
            var schemas = jsonSchemaService.GetCmsConfiguration();

            foreach (var menuItem in schemas.MenuItems)
            {
                if (menuItem.Key != null)
                {
                    var(allItems, _) = await dataProviderService.List(menuItem.Key, null, null);

                    foreach (var item in allItems)
                    {
                        await dataProviderService.Delete(menuItem.Key, item.Id, null, null);
                    }
                }
            }

            string cmsTreeType = PageTreeRoutes.PageTreeType;
            var    tree        = await cmsTreeService.GetCmsTreeItem(cmsTreeType, null);

            foreach (var item in tree.Nodes)
            {
                await cmsTreeService.ClearCmsTreeNode(cmsTreeType, item.NodeId, null, null);
            }
        }
コード例 #3
0
        public async Task <IActionResult> Delete([FromRoute] string cmsType, [FromRoute] Guid id, [FromRoute] string?lang, [FromQuery] string?treeItemSchemaKey, [FromQuery] Guid?treeNodeId)
        {
            if (id == Guid.Empty)
            {
                return(new NotFoundResult());
            }

            var cmsMenuItem = schemaService.GetCmsType(cmsType);

            if (cmsMenuItem == null)
            {
                return(new NotFoundResult());
            }

            var schemaKey            = cmsMenuItem.SchemaKey;
            List <CmsTreeNode> nodes = new List <CmsTreeNode>();

            if (cmsMenuItem.IsTree)
            {
                nodes = await cmsTreeService.GetCmsTreeNodesForCmsItemId(cmsType, id, lang);

                if (nodes.Any())
                {
                    schemaKey = nodes.First().CmsItemType;
                }
                else
                {
                    schemaKey = treeItemSchemaKey;
                    if (treeNodeId.HasValue)
                    {
                        nodes = await cmsTreeService.GetCmsTreeNodesForNodeId(cmsType, treeNodeId.Value, lang);
                    }
                }


                if (schemaKey == null)
                {
                    //TODO: Forward to pick a schema
                }
            }

            if (schemaKey == null)
            {
                return(new NotFoundResult());
            }

            var schema = schemaService.GetSchema(schemaKey);

            if (schema == null)
            {
                return(new NotFoundResult());
            }

            var data = await readCmsItemService.Read <CmsItem>(cmsType, id, lang).ConfigureAwait(false);

            var model = new EditViewModel
            {
                CmsType           = cmsType,
                Id                = id,
                SchemaLocation    = schema,
                MenuCmsItem       = cmsMenuItem,
                CmsConfiguration  = schemaService.GetCmsConfiguration(),
                Language          = lang,
                Data              = data,
                Nodes             = nodes,
                TreeItemSchemaKey = treeItemSchemaKey,
                TreeNodeId        = treeNodeId
            };

            return(View("Delete", model));
        }