ContentController.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 » ContentController.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.IO;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using System.Web.Mvc;
using System.Text;

using Everest.CmsServices.Models;
using Everest.CmsServices.Services;

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

using Everest.CmsServices.Search;
using Everest.Library.Versioning;
using Everest.CmsServices.Providers;
namespace Everest.CmsServices.Controllers{
    /// <summary>
    /// 
    /// </summary>
    [ValidateInput(false)]
    [PermissionFilter(Permission = FolderType.Content)]
    public class ContentController : CmsExtController
    {
        IEverestCmsDataContext dataContext = EverestCmsEntities.GetDataContext();
        IContentProvider contentProvider;
        TextContentService contentService = UnityManager.Resolve<TextContentService>();

        #region Form

        IGeneratorFactory factory;

        public ContentController(IGeneratorFactory factory, IContentProvider contentProvider)
        {
            this.factory = factory;
            this.contentProvider = contentProvider;
        }
        public string GetForm(string schema, string formType)
        {
            return GetForm(schema, formType, Request.Form);
        }

        private string GetForm(string schema, string formType, NameValueCollection nameValues)
        {
            IFormGenerator generator = factory.GetGenerator(formType);
            return generator.Generate(schema, nameValues);
        }
        public ActionResult Edit(int contentId, string application)
        {
            var content = dataContext.QueryContent(contentId).Select(c => new { c.aspnet_Applications.ApplicationName, FolderUUID = c.Cms_Folder.UUID, SchemaUUID = c.Cms_Schema.UUID }).First();

            NameValueCollection nameValues = new NameValueCollection();
            nameValues.Add("folderUUID", content.FolderUUID.ToString());
            nameValues.Add("application", content.ApplicationName);


            string formScript = GetForm(content.SchemaUUID.ToString(), "form", nameValues);
            ViewData["FormScript"] = formScript;
            ViewData["ContentId"] = contentId;
            return View();
        }
        #endregion

        #region IStandardActions Members

        /// <summary>
        /// Gets the list.
        /// </summary>
        /// <returns></returns>
        public ActionResult GetList()
        {
            int start, limit;
            EnsurePaging(out start, out limit);
            var folderUUID = Request.Form["folderUUID"].GetNullableGuid();
            string app = Request.Form["application"];
            Guid schemaUUID = new Guid(Request.Form["schemaUUID"]);
            Guid? parentUUID = Request.Form["parentUUID"].GetNullableGuid();

            StringBuilder expression = new StringBuilder("1=1");

            string title = Request.Form["Title"];
            if (!StringExtensions.IsNullOrEmptyTrim(title))
            {
                expression.Append(" AND Title LIKE '%' + {Title} + '%'");
            }
            string userKey = Request.Form["UserKey"];
            if (!StringExtensions.IsNullOrEmptyTrim(userKey))
            {
                expression.Append(" AND UserKey LIKE '%' + {UserKey} + '%'");
            }
            string orderStatement = GetOrderStatement();
            bool? isProcessed = null;
            if (Request.Form["Processed"] == "0")
            {
                isProcessed = false;
            }
            if (Request.Form["Processed"] == "1")
            {
                isProcessed = true;
            }
            IEnumerable<IDictionary<string, object>> contents;
            int contentCount;
            if (parentUUID != null)
            {
                contents = contentService.QuerySubContents(schemaUUID, parentUUID.Value, expression.ToString(), Request.Form, orderStatement, start, limit, out contentCount);
            }
            else
            {
                contents = contentService.QueryContents(folderUUID.Value, expression.ToString(), Request.Form, orderStatement, User.Identity.Name, isProcessed, start, limit, out contentCount);
            }

            return Json(new ExtJsonReaderObject(contents, contentCount));
        }

        /// <summary>
        /// Gets the details.
        /// </summary>
        /// <returns></returns>
        public ActionResult GetDetail()
        {
            var contentUUID = new Guid(Request.Form["UUID"]);
            JsonResultData resultData = new JsonResultData();

            IDictionary<string, object> dic = contentService.QueryContent(contentUUID, User.Identity.Name);
            dic["FormTitle"] = dic["Title"];
            resultData.data = dic;

            return Json(resultData);
        }


        /// <summary>
        /// Submits the specified add.
        /// </summary>
        /// <param name="add">if set to <c>true</c> [add].</param>
        /// <param name="closeForm"></param>
        /// <returns></returns>
        public ActionResult Submit(bool add, bool? closeForm)
        {
            JsonResultData resultData = new JsonResultData();
            Cms_Content content;

            try
            {
                if (add)
                {
                    content = contentService.AddContent(Request.Form, User.Identity.Name, Request.Files);
                }
                else
                {
                    content = contentService.UpdateContent(Request.Form, User.Identity.Name, Request.Files, true);
                }
                if (closeForm.Value == false && resultData.success == true)
                {
                    resultData.closeForm = false;
                    resultData.data = contentService.QueryContent(content.UUID, User.Identity.Name);
                }
            }
            catch (RuleViolationException ruleException)
            {
                ruleException.Issues.UpdateResultDataWithViolations(resultData);
                Everest.Library.HealthMonitor.HealthMonitoringLogging.LogError(ruleException);
            }
            catch (Exception ex)
            {
                resultData.AddError("Title", ex.Message);
                Everest.Library.HealthMonitor.HealthMonitoringLogging.LogError(ex);
            }

            return Json(resultData);
        }

        public ActionResult Delete(Guid[] uuid)
        {
            var resultData = new JsonResultData() { success = true };
            foreach (var guid in uuid)
            {
                contentService.Delete(guid, User.Identity.Name);
            }

            return Json(resultData);
        }
        #endregion

        #region Localize
        /// <summary>
        /// Localizes the specified content id.
        /// </summary>
        /// <param name="contentId">The content id.</param>
        /// <param name="folderUUID">The folder UUID.</param>
        /// <returns></returns>
        public ActionResult Localize(Guid uuid, Guid folderUUID)
        {
            JsonResultData resultData = new JsonResultData();

            TextContentService textContentService = UnityManager.Resolve<TextContentService>();
            var content = textContentService.Localize(uuid, folderUUID, User.Identity.Name);
            resultData.data = new
            {
                content.UUID,
                content.Title,
                content.UserName
            };
            return Json(resultData);
        }
        #endregion

        #region MultiSelect
        #region TextContent
        public ActionResult GetReferencingTextContents(Guid[] UUID, Guid schemaUUID, string applicationName, string title)
        {
            StringBuilder queryStatement = new StringBuilder("1=1");
            if (!StringExtensions.IsNullOrEmptyTrim(title))
            {
                queryStatement.Append(" AND Title LIKE '%' + {Title} + '%'");
            }
            if (UUID != null && UUID.Length > 0)
            {
                foreach (var guid in UUID)
                {
                    queryStatement.AppendFormat(" AND UUID <> '{0}'", guid);
                }
            }

            return Json(QueryReferencingTextContents(schemaUUID, applicationName, queryStatement.ToString()));
        }
        private ExtJsonReaderObject QueryReferencingTextContents(Guid schemaUUID, string application, string queryStatement)
        {
            int start, limit;
            this.EnsurePaging(out start, out limit);
            string orderStatement = GetOrderStatement();
            int count;

            var contents = contentService.QueryContentsBySchema(schemaUUID, application, queryStatement, orderStatement, Request.Form, start, limit, out count, null);
            foreach (var item in contents)
            {
                if (item["FolderUUID"] != DBNull.Value)
                {
                    item.Add("FolderName", CachedData.GetFolder((Guid)item["FolderUUID"]).FolderName);
                }
            }
            return new ExtJsonReaderObject(contents, count);
        }

        public ActionResult GetReferencingTextContentsSelected(Guid[] UUID, Guid schemaUUID, string applicationName)
        {
            StringBuilder queryStatement = new StringBuilder("1 <> 1");

            if (UUID != null && UUID.Length > 0)
            {
                foreach (var guid in UUID)
                {
                    queryStatement.AppendFormat(" OR UUID = '{0}'", guid);
                }
                return Json(QueryReferencingTextContents(schemaUUID, applicationName, queryStatement.ToString()));
            }
            return null;

        }
        #endregion

        #region Select Binary Content
        public ActionResult GetReferencingBinaryContents(Guid[] UUID, Guid schemaUUID, string applicationName, string title)
        {
            Expression<Func<Cms_Content, bool>> expression = c => true;
            if (!StringExtensions.IsNullOrEmptyTrim(title))
            {
                expression = expression.And(c => c.Title.Contains(title.Trim()));
            }
            if (UUID != null && UUID.Length > 0)
            {
                expression = expression.And((EfUtility.BuildNotInExpression<Cms_Content, Guid>(c => c.UUID, UUID)));

            }
            return Json(GetBinaryContentsBySchema(schemaUUID, applicationName, expression));
        }

        public ActionResult GetReferencingBinaryContentsSelected(Guid[] UUID, Guid schemaUUID, string applicationName)
        {
            if (UUID != null && UUID.Length > 0)
            {
                var expression = (EfUtility.BuildContainsExpression<Cms_Content, Guid>(c => c.UUID, UUID));
                return Json(GetBinaryContentsBySchema(schemaUUID, applicationName, expression));
            }
            return null;
            //return this.GetReferencingTextContentsSelected(keyColumnValues, schemaUUID, applicationName, title);
        }
        private ExtJsonReaderObject GetBinaryContentsBySchema(Guid schemaUUID, string applicationName, Expression<Func<Cms_Content, bool>> expression)
        {
            int start, limit;
            this.EnsurePaging(out start, out limit);

            IQueryable<Cms_Content> queryable = dataContext.QueryContents(applicationName, schemaUUID).Where(expression).OrderByDescending(c => c.ContentId);

            var count = queryable.Count();

            queryable = OrderByRequest(queryable);

            var contents = queryable.Select(c => new
            {
                c.UUID,
                c.Title,
                c.Cms_Folder.FolderName,
                Application = c.aspnet_Applications.ApplicationName,
                c.Cms_BinaryContent.FilePath
            }).ToArray().Select(c => new
            {
                c.UUID,
                c.Title,
                c.FolderName,
                c.Application,
                FileUrl = Url.Content(c.FilePath)
            });
            return new ExtJsonReaderObject(contents.Skip(start).Take(limit), count);
        }
        #endregion
        #endregion

        #region Relations
        public ActionResult UsedBy(Guid uuid, string dataUrl)
        {
            IList<Dictionary<string, object>> treeNodes = contentService.UserBy(uuid, dataUrl);
            return Json(treeNodes);
        }
        #endregion

        #region Including
        public ActionResult Include(Guid contentUUID, Guid folderUUID)
        {
            JsonResultData resultData = new JsonResultData();
            contentService.Include(contentUUID, folderUUID);
            return Json(resultData);
        }
        public ActionResult Exclude(Guid contentUUID, Guid folderUUID)
        {
            JsonResultData resultData = new JsonResultData();

            contentService.Exclude(contentUUID, folderUUID);
            return Json(resultData);
        }
        #endregion

        #region Content View
        public ActionResult GetView()
        {
            //int start, limit;
            //EnsurePaging(out start, out limit);
            //string app = Request.Form["application"];
            //Guid schemaUUID = new Guid(Request.Form["schemaUUID"]);

            //string title = Request.Form["Title"];

            //var queryable = dataContext.QueryContents(schemaUUID, app, title).OrderByDescending(c => c.ContentId).Select(c => new
            //{
            //    c.ContentId,
            //    c.UUID,
            //    c.Title,
            //    Application = c.aspnet_Applications.ApplicationName,
            //    c.UserName,
            //    c.PostDate,
            //    c.ContentStatus
            //});
            //return Json(new ExtJsonReaderObject(queryable.Skip(start).Take(limit).ToArray(), queryable.Count()));


            int start, limit;
            EnsurePaging(out start, out limit);
            string app = Request.Form["application"];
            Guid schemaUUID = new Guid(Request.Form["schemaUUID"]);

            StringBuilder expression = new StringBuilder(" 1=1 ");

            string title = Request.Form["Title"];
            if (!StringExtensions.IsNullOrEmptyTrim(title))
            {
                expression.Append(" AND Title LIKE '%' + {Title} + '%'");
            }
            string userKey = Request.Form["UserKey"];
            if (!StringExtensions.IsNullOrEmptyTrim(userKey))
            {
                expression.Append(" AND UserKey LIKE '%' + {UserKey} + '%'");
            }

            var folderUUID = new Guid(Request.Form["folderUUID"]);
            var folder = CachedData.GetFolder(folderUUID);
            if (!string.IsNullOrEmpty(folder.Condition))
            {
                expression.AppendFormat("AND {0}", folder.Condition);
            }

            string orderStatement = GetOrderStatement();

            IEnumerable<IDictionary<string, object>> contents;
            int contentCount;
            contents = contentService.QuerySubContents(schemaUUID, null, expression.ToString(), Request.Form, orderStatement, start, limit, out contentCount);


            return Json(new ExtJsonReaderObject(contents, contentCount));
        }
        #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.