FolderController.cs :  » Content-Management-Systems-CMS » Kooboo » Everest » CmsServices » Controllers » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Content Management Systems CMS » Kooboo 
Kooboo » Everest » CmsServices » Controllers » FolderController.cs
/*
Kooboo is a content management system based on ASP.NET MVC framework. Copyright 2009 Yardi Technology Limited.

This program is free software: you can redistribute it and/or modify it under the terms of the
GNU General Public License version 3 as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program.
If not, see http://www.kooboo.com/gpl3/.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;

using Everest.Library.Data.Entity;
using Everest.Library;
using Everest.Library.Data.Rule;
using Everest.Library.Mvc;
using Everest.Library.Extjs;
using Everest.Library.Extjs.Tree;
using Everest.Library.Json;
using Everest.Library.ExtensionMethod;
using Everest.Library.Data;
using Microsoft.Data.Extensions;

using Everest.CmsServices.Models;
using Everest.CmsServices.Services;
using Everest.CmsServices.Providers;
namespace Everest.CmsServices.Controllers{
    /// <summary>
    /// 
    /// </summary>
    public class FolderController : ExtControllerBase
    {
        IEverestCmsDataContext dataContext = EverestCmsEntities.GetDataContext();
        FolderService folderService = UnityManager.Resolve<FolderService>();
        #region Submit Content Folder

        /// <summary>
        /// Submits the add folder.
        /// </summary>
        /// <param name="add">if set to <c>true</c> [add].</param>
        /// <returns></returns>
        [PermissionFilter(Permission = FolderType.ContentFolder)]
        public ActionResult SubmitContentFolder(bool add, Guid? parentFolderUUID, Guid? folderUUID)
        {
            var result = SaveFolder(add, parentFolderUUID, folderUUID, FolderType.TextContent);
            return Json(result);
        }
        /// <summary>
        /// Submits the content view folder.
        /// </summary>
        /// <param name="add">if set to <c>true</c> [add].</param>
        /// <returns></returns>
        [PermissionFilter(Permission = FolderType.ContentFolder)]
        public ActionResult SubmitContentViewFolder(bool add, Guid? parentFolderUUID, Guid? folderUUID)
        {
            var resultData = SaveFolder(add, parentFolderUUID, folderUUID, FolderType.ContentView);

            return Json(resultData);
        }
        /// <summary>
        /// Saves the folder.
        /// </summary>
        /// <param name="add">if set to <c>true</c> [add].</param>
        /// <param name="folderUUID">The folder UUID.</param>
        /// <param name="folderType">Type of the folder. FolderType.ContentView|TextContentFolder</param>
        /// <param name="schema">The schema.</param>
        /// <returns></returns>
        private JsonResultData SaveFolder(bool add, Guid? parentFolderUUID, Guid? folderUUID, FolderType folderType)
        {
            JsonResultData resultData = new JsonResultData() { success = true };
            try
            {
                Cms_Folder folder = null;
                if (add)
                {
                    folder = folderService.CreateFolder(parentFolderUUID.Value, Request.Form, folderType);
                }
                else
                {
                    folder = folderService.SaveFolder(folderUUID.Value, Request.Form);
                }
            }
            catch (RuleViolationException ruleException)
            {
                ruleException.Issues.UpdateResultDataWithViolations(resultData);
                Everest.Library.HealthMonitor.HealthMonitoringLogging.LogError(ruleException);
            }
            return resultData;
        }

        /// <summary>
        /// Deletes the content folder.
        /// </summary>
        /// <returns></returns>
        [PermissionFilter(Permission = FolderType.ContentFolder)]
        public ActionResult DeleteFolder(Guid folderUUID)
        {
            JsonResultData resultData = new JsonResultData();
            folderService.DeleteFolder(folderUUID);
            return Json(resultData);
        }

        #endregion

        #region Properties

        ///// <summary>
        ///// Submits the folder's properties.
        ///// </summary>
        ///// <returns></returns>
        //public ActionResult SubmitProperties()
        //{
        //    JsonResultData resultData = new JsonResultData();
        //    var folderUUID = new Guid(Request.Form["FolderUUID"]);
        //    SaveProperties(folderUUID);
        //    return Json(resultData);
        //}
        ///// <summary>
        ///// Saves the properties.
        ///// </summary>
        ///// <param name="folderUUID">The folder UUID.</param>
        //private void SaveProperties(Guid folderUUID)
        //{
        //    folderService.SaveProperties(dataContext.QueryFolder(folderUUID).First(), Request.Form);
        //}

        /// <summary>
        /// Gets the folder's properties.
        /// </summary>
        /// <param name="folderUUID">The folder UUID.</param>
        /// <returns></returns>
        public ActionResult GetProperties(Guid folderUUID)
        {
            JsonResultData resultData = new JsonResultData();
            var folder = dataContext.QueryFolder(folderUUID).First();

            var defaultDic = new Dictionary<string, object>();
            defaultDic.Add("FolderUUID", folderUUID.ToString());
            defaultDic.Add("FolderName", folder.FolderName);
            defaultDic.Add("DisplayName", folder.DisplayName);
            defaultDic.Add("SchemaUUID", folder.SchemaUUIDReference.ToString());
            defaultDic.Add("Workflow", folder.WorkflowUUIDReference.ToString());
            defaultDic.Add("Base", folder.BaseReference.EntityKey.GetKeyValue<Guid?>("UUID").ToString());
            defaultDic.Add("IncludeItems", folder.IncludeBase);
            if ((FolderType)folder.FolderType == FolderType.ContentView)
            {
                defaultDic.Add("Condition", folder.Condition);
            }
            resultData.data = defaultDic;

            return Json(resultData);
        }

        #endregion

        #region combobox
        /// <summary>
        /// Gets the content folders.
        /// </summary>
        /// <param name="application">The application.</param>
        /// <returns></returns>
        public ActionResult GetContentFolders(string application)
        {
            IEnumerable<string> baseApplications = CachedData.GetBaseApplications(application);

            var folders = dataContext.QueryFolders(baseApplications, FolderType.TextContent, FolderType.BinaryContent)
                .Select(f => new UniqueName() { ApplicationName = f.aspnet_Applications.ApplicationName, ItemName = f.FolderName })
                .OrderBy(f => f.ApplicationName);
            var items = folders.ToComboboxItems<UniqueName>(f => f.ToString(), f => f.ToString(), true);
            return Json(new ExtJsonReaderObject(items, items.Count));
        }
        /// <summary>
        /// Gets the text content folders.
        /// Be used in Search setting.
        /// </summary>
        /// <param name="application">The application.</param>
        /// <returns></returns>
        public ActionResult GetTextContentFoldersForSearch(string application)
        {
            IEnumerable<string> baseApplications = CachedData.GetBaseApplications(application);

            var folders = dataContext.QueryFolders(baseApplications, FolderType.TextContent)
                .QueryLocalizes(application)
                .Select(f => new UniqueName() { ApplicationName = f.aspnet_Applications.ApplicationName, ItemName = f.FolderName })
                .OrderBy(f => f.ApplicationName);
            var items = folders.ToComboboxItems<UniqueName>(f => f.ToString(), f => f.ToString(), true);
            return Json(new ExtJsonReaderObject(items, items.Count));
        }

        /// <summary>
        /// Gets the content folder fo combobox.
        /// </summary>
        /// <param name="application">The application.</param>
        /// <param name="folderType">Type of the folder.</param>
        /// <returns></returns>
        public ActionResult GetSameSchemaBaseFolder(string application, Guid? schemaUUID, Guid? folderUUID)
        {
            if (schemaUUID == null)
            {
                throw new Exception(Resources.SchemaMustBeSelected);
            }
            //var schemaUUID = new Guid(schemaUUID);
          

            var app = CachedData.GetApplication(application);
            //var contentFolder = dataContext.QueryFolders(application, FolderType.Content).First();

            var folderQuery = dataContext.QueryFoldersBySchema(schemaUUID.Value)
                            .Where(f => f.ApplicationLevel < app.ApplicationLevel)
                              .Select(f => new
                              {
                                  f.aspnet_Applications.ApplicationName,
                                  f.FolderPath,
                                  f.UUID
                              });

            if (folderUUID.HasValue)
            {
                folderQuery = folderQuery.Where(f => f.UUID != folderUUID.Value);
            }

            var folders = folderQuery.ToArray();

            PermissionService permissionService = UnityManager.Resolve<PermissionService>();

            var canAccessFolders = folders.Where(f => permissionService.CanAccessApplication(User.Identity.Name, f.ApplicationName));

            var items = canAccessFolders.ToComboboxItems(f => f.FolderPath.ToString(), f => f.UUID.ToString(), true);
            return Json( new ExtJsonReaderObject(items, items.Count));
        }
        //public ActionResult GetTextContentFolderBySchema(string application)
        //{
        //    return GetSameSchemaBaseFolder(application, FolderType.TextContent);
        //}
        //public ActionResult GetBinaryContentFolderBySchema(string application)
        //{
        //    return GetSameSchemaBaseFolder(application, FolderType.BinaryContent);
        //}

        #endregion

        #region Relations
        public ActionResult UsedBy(Guid uuid, string dataUrl, bool? isApplication)
        {
            IList<Dictionary<string, object>> treeNodes = new List<Dictionary<string, object>>();

            // It is not a application folder node
            if (isApplication == null || isApplication.Value == false)
            {
                #region SearchSetting
                //folder used in SearchSetting
                var searchSettingNode = new TreeNode();
                searchSettingNode.Text = Resources.TreeNode_SearchSetting;
                searchSettingNode.Leaf = false;
                searchSettingNode.Expanded = true;
                searchSettingNode.children = new List<IDictionary<string, object>>();
                treeNodes.Add(searchSettingNode.Attributes);
                var searchSettings = dataContext.QuerySearchSettings(uuid)
                    .Select(s => new
                    {
                        s.aspnet_Applications.ApplicationName
                    });
                foreach (var setting in searchSettings)
                {
                    var treeNode = new TreeNode();
                    searchSettingNode.children.Add(treeNode.Attributes);
                    treeNode.Text = setting.ApplicationName;
                    treeNode.IconCls = "SearchSetting";
                    treeNode.Leaf = true;
                }
                #endregion

                #region DataRule
                //folder used in content template.
                var contentTemplatesNode = new TreeNode();
                contentTemplatesNode.Text = Resources.TreeNode_ContentTemplate;
                contentTemplatesNode.Leaf = false;
                contentTemplatesNode.Expanded = true;
                contentTemplatesNode.children = new List<IDictionary<string, object>>();
                treeNodes.Add(contentTemplatesNode.Attributes);

                //folder used in page.
                var pagesNode = new TreeNode();
                pagesNode.Text = Resources.TreeNode_Page;
                pagesNode.Leaf = false;
                pagesNode.Expanded = true;
                pagesNode.children = new List<IDictionary<string, object>>();
                treeNodes.Add(pagesNode.Attributes);

                var dataRules = dataContext.QueryDataRulesByFolder(uuid).Select(dr => new
                {
                    dr.Cms_Page,
                    dr.Cms_ContentTemplate,
                    Application = dr.Cms_Page != null ? dr.Cms_Page.aspnet_Applications.ApplicationName : dr.Cms_ContentTemplate.aspnet_Applications.ApplicationName
                });
                foreach (var dataRule in dataRules)
                {
                    if (dataRule.Cms_Page != null)
                    {
                        var treeNode = new TreeNode();
                        pagesNode.children.Add(treeNode.Attributes);
                        treeNode.Text = new UniqueName(dataRule.Application, dataRule.Cms_Page.PageName).ToString();
                        treeNode.Attributes.Add("uuid", dataRule.Cms_Page.UUID);
                        treeNode.IconCls = "PageNode";
                        treeNode.Attributes.Add("dataUrl", "Kooboo_Page/UsedBy");
                    }
                    if (dataRule.Cms_ContentTemplate != null)
                    {
                        var treeNode = new TreeNode();
                        contentTemplatesNode.children.Add(treeNode.Attributes);
                        treeNode.Text = new UniqueName(dataRule.Application, dataRule.Cms_ContentTemplate.Name).ToString();
                        treeNode.IconCls = "ContentTemplate";
                        treeNode.Attributes.Add("uuid", dataRule.Cms_ContentTemplate.UUID);
                        treeNode.Attributes.Add("dataUrl", "Kooboo_ContentTemplate/UsedBy");
                    }
                }

                #endregion
            }

            #region Inheritance
            //inherited by
            var inheritedByNode = new TreeNode();
            inheritedByNode.Text = Resources.InheritedBy;
            inheritedByNode.Leaf = false;
            inheritedByNode.Expanded = true;
            inheritedByNode.children = new List<IDictionary<string, object>>();
            treeNodes.Add(inheritedByNode.Attributes);
            var inheritedByFolders = dataContext.QueryFoldersByBase(uuid).Select(f =>
                new
                {
                    f.aspnet_Applications.ApplicationName,
                    f.FolderName,
                    f.FolderType,
                    f.UUID
                });
            foreach (var item in inheritedByFolders)
            {
                var treeNode = new TreeNode();
                inheritedByNode.children.Add(treeNode.Attributes);
                treeNode.Text = new UniqueName(item.ApplicationName, item.FolderName).ToString();
                treeNode.Attributes.Add("uuid", item.UUID);
                treeNode.Attributes.Add("dataUrl", dataUrl);
                treeNode.IconCls = ((FolderType)item.FolderType).ToString();
            }

            //inherit from
            var inheritFromNode = new TreeNode();
            inheritFromNode.Text = Resources.InheritFrom;
            inheritFromNode.Leaf = false;
            inheritFromNode.Expanded = true;
            inheritFromNode.children = new List<IDictionary<string, object>>();
            treeNodes.Add(inheritFromNode.Attributes);
            var inheritFromFolder = dataContext.QueryBaseFolder(uuid).Select(f =>
                new
                {
                    f.aspnet_Applications.ApplicationName,
                    f.FolderName,
                    f.FolderType,
                    f.UUID
                });
            foreach (var item in inheritFromFolder)
            {
                var treeNode = new TreeNode();
                inheritFromNode.children.Add(treeNode.Attributes);
                treeNode.Text = new UniqueName(item.ApplicationName, item.FolderName).ToString();
                treeNode.Attributes.Add("uuid", item.UUID);
                treeNode.Attributes.Add("dataUrl", dataUrl);
                treeNode.IconCls = ((FolderType)item.FolderType).ToString();
            }
            #endregion

            return Json(treeNodes);
        }
        #endregion
    }
}

www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.