Exemple #1
0
        public async Task <IActionResult> Edit([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());
            }

            return(RedirectToAction("Edit", "JsonEditor", this.Request.RouteValues));
        }
Exemple #2
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));
        }