Esempio n. 1
0
        public async Task CreateTestData()
        {
            //Create a category
            var categoryId = await CreateCategory("Fruit");

            //Create a product
            await CreateProduct("Banana", 42);
            await CreateProduct("Apple", 3);
            await CreateProduct("Kiwi", 16);

            //Singleton page
            await CreateSingletonPage();


            string cmsTreeType = PageTreeRoutes.PageTreeType;;
            var    homepageId  = await CreateTestPage("homepage", "Welcome to the sample homepage");

            await cmsTreeService.CreateOrUpdateCmsTreeNodeForSlug(cmsTreeType, "/", new CmsTreeNode {
                CmsItemId   = homepageId,
                CmsItemType = "contentpage"
            }, null, null);

            var contentPageId = await CreateTestPage("test", "Welcome to a sample content page");

            await cmsTreeService.CreateOrUpdateCmsTreeNodeForSlug(cmsTreeType, "/test", new CmsTreeNode
            {
                CmsItemId   = contentPageId,
                CmsItemType = "contentpage"
            }, null, null);
        }
Esempio n. 2
0
        public async Task <IActionResult> EditTree([FromRoute] string cmsTreeType, [FromRoute] string slug, [FromQuery] string?treeItemSchemaKey, [FromQuery] string?lang)
        {
            slug ??= string.Empty;
            slug = slug.TrimStart('/');
            slug = "/" + slug;


            var cmsMenuItem = schemaService.GetCmsType(cmsTreeType);

            if (cmsMenuItem == null || !cmsMenuItem.SchemaKeys.Any())
            {
                return(new NotFoundResult());
            }

            CmsTreeNode?cmsTreeItem = await cmsTreeService.GetCmsTreeNode(cmsTreeType, slug, lang).ConfigureAwait(false);

            if (cmsTreeItem == null)
            {
                cmsTreeItem = await cmsTreeService.CreateOrUpdateCmsTreeNodeForSlug(cmsTreeType, slug, new CmsTreeNode()
                {
                    CmsItemId = Guid.NewGuid()
                }, lang, this.User.Identity?.Name);
            }

            if (string.IsNullOrEmpty(cmsTreeItem.CmsItemType) && string.IsNullOrEmpty(treeItemSchemaKey))
            {
                EditTreeViewModel vm = new EditTreeViewModel
                {
                    MenuCmsItem       = cmsMenuItem,
                    CmsType           = cmsTreeType,
                    Language          = lang,
                    TreeItemSchemaKey = treeItemSchemaKey,
                    TreeNodeId        = cmsTreeItem?.NodeId
                };

                return(View(vm));
            }

            Guid?id = cmsTreeItem.CmsItemId;

            if (!id.HasValue)
            {
                id = Guid.NewGuid();
            }

            return(RedirectToAction("Edit", new { cmsType = cmsTreeType, id = id, lang = lang, treeItemSchemaKey = treeItemSchemaKey, treeNodeId = cmsTreeItem.NodeId }));
        }