Beispiel #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));
        }
Beispiel #2
0
        public async Task <IActionResult> List([FromRoute] string cmsType, [FromQuery] string?sortField, [FromQuery] string?sortOrder, [FromQuery] int pageIndex, [FromQuery] string?q)
        {
            ViewBag.SortField   = sortField;
            ViewBag.SortOrder   = sortOrder;
            ViewBag.SearchQuery = q;

            var cmsMenuItem = schemaService.GetCmsType(cmsType);

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

            if (cmsMenuItem.IsTree)
            {
                return(await ListTree(cmsType, null, q));
            }

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

            var schema = schemaService.GetSchema(cmsMenuItem.SchemaKey);

            if (schema == null)
            {
                throw new Exception($"schema not found for key: {cmsMenuItem.SchemaKey}");
            }

            int pageSize = cmsMenuItem.PageSize;

            if (pageSize <= 0)
            {
                pageSize = 20;
            }

            var(results, total) = await readCmsItemService.List(cmsType, sortField, sortOrder, pageSize : pageSize, pageIndex, q).ConfigureAwait(false);

            if (cmsMenuItem.IsSingleton)
            {
                if (results.Any())
                {
                    return(RedirectToAction("Edit", "Edit", new { cmsType = cmsType, id = results.First().Id }));
                }
                else
                {
                    return(RedirectToAction("Create", "Edit", new { cmsType = cmsType }));
                }
            }

            var model = new ListViewModel
            {
                CmsType     = cmsType,
                Schema      = schema,
                MenuCmsItem = cmsMenuItem,
                Items       = results,
                TotalPages  = total,
                CurrentPage = pageIndex + 1,
                PageSize    = pageSize
            };

            return(View(model));
        }
Beispiel #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));
        }