ApplicationController.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 » ApplicationController.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.Data.Objects;
using System.Web.Mvc;
using System.Web.Security;

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

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

namespace Everest.CmsServices.Controllers{
    public class ApplicationController : CmsExtController
    {
        IEverestCmsDataContext dataContext = EverestCmsEntities.GetDataContext();

        public ApplicationController()
        {

        }

        #region combobox
        /// <summary>
        /// Gets the applications.
        /// </summary>
        /// <param name="excludeRoot">The exclude root.</param>
        /// <returns></returns>
        public ActionResult GetApplicationsForCombobox(string rootName)
        {
            var applications = dataContext.aspnet_Applications.Where(a => a.ApplicationName != CmsGlobal.RootApplicationName);

            var data = applications.ToComboboxItems<aspnet_Applications>(a => a.ApplicationName, a => a.ApplicationName, false);

            //
            var permissionService = UnityManager.Resolve<PermissionService>();
            var items = data.Where(item => permissionService.CanAccessApplication(User.Identity.Name, item.Name)).ToList();

            if (string.IsNullOrEmpty(rootName))
            {
                items.Insert(0, new ComboboxItem(CmsGlobal.RootApplicationName, CmsGlobal.RootApplicationName));
            }
            else
            {
                items.Insert(0, new ComboboxItem(rootName, CmsGlobal.RootApplicationName));
            }
            return Json(new ExtJsonReaderObject(items, items.Count()));
        }
        public ActionResult GetBaseApplications(string application, string baseApplication)
        {
            if (StringExtensions.IsNullOrEmptyTrim(application))
            {
                application = baseApplication;
            }
            var baseApps = CachedData.GetBaseApplications(application);

            var items = baseApps.ToComboboxItems(s => s, s => s, true);

            return Json(new ExtJsonReaderObject(items, items.Count));
        }
        public ActionResult GetStatusCode()
        {
            string[] names = Enum.GetNames(typeof(HttpStatusCode));

            var items = names.ToComboboxItems(s => s, s => s, false);
            return Json(new ExtJsonReaderObject(items, items.Count));
        }
        #endregion

        #region IStandardActions Members

        public ActionResult GetList()
        {
            throw new NotImplementedException();
        }
        [PermissionFilter(Permission = FolderType.Application)]
        public ActionResult GetDetail(string application)
        {
            JsonResultData resultData = new JsonResultData();
            var app = dataContext.QueryApplication(application)
                .Select(a => new
                {
                    a.ApplicationId,
                    a.ApplicationName,
                    a.BaseApplication,
                    a.HostName,
                    a.Theme,
                    a.VirtualPath,
                    a.Javascript
                }).First();
            resultData.data = app;
            return Json(resultData);

        }
        [PermissionFilter(Permission = FolderType.Application)]
        public ActionResult Submit(bool add, bool? closeForm)
        {
            JsonResultData formResult = new JsonResultData() { success = true };
            try
            {
                string theme = Request.Form["Theme"];
                string hostName = Request.Form["HostName"];
                string javascript = Request.Form["Javascript"];
                string virtualPath = Request.Form["VirtualPath"];
                if (add)
                {
                    string applicationName = Request.Form["ApplicationName"];
                    string baseApplication = Request.Form["BaseApplication"];

                    ApplicationService service = UnityManager.Resolve<ApplicationService>();
                    service.CreateApplication(applicationName, baseApplication, hostName, theme, javascript, virtualPath, User.Identity.Name);

                }
                else
                {
                    string applicationName = Request.Form["oldData.ApplicationName"];
                    var app = dataContext.QueryApplication(applicationName).First();

                    app.HostName = hostName;
                    app.Theme = theme;
                    app.Javascript = javascript;
                    app.VirtualPath = virtualPath;

                    dataContext.SaveChanges();

                }
            }
            catch (RuleViolationException ruleException)
            {
                ruleException.Issues.UpdateResultDataWithViolations(formResult);
                Everest.Library.HealthMonitor.HealthMonitoringLogging.LogError(ruleException);
            }

            return Json(formResult);
        }
        [PermissionFilter(Permission = FolderType.Application)]
        public ActionResult Delete()
        {
            ApplicationService service = UnityManager.Resolve<ApplicationService>();
            string applicationName = Request.Form["ApplicationName"];
            service.RemoveApplication(applicationName);
            return Json(new JsonResultData() { success = true });
        }

        #endregion

        #region Application Settings
        [PermissionFilter(Permission = FolderType.Application)]
        public ActionResult GetSettings(string application)
        {
            JsonResultData resultData = new JsonResultData();
            resultData.data = GetApplicationSettings(application);
            return Json(resultData);
        }
        private object GetApplicationSettings(string application)
        {
            var app = dataContext.QueryApplication(application)
                .Select(a => new
                {
                    a.ApplicationId,
                    a.ApplicationName,
                    a.DisplayName,
                    a.Theme,
                    a.HostName,
                    a.Javascript,
                    a.Release,
                    a.VirtualPath,
                    CustomErrors = a.Cms_CustomError.Select(c => new
                    {
                        c.StatusCode,
                        c.Redirect
                    })
                })
                .First();
            return new
            {
                app.ApplicationId,
                app.ApplicationName,
                app.DisplayName,
                app.Theme,
                app.HostName,
                app.Javascript,
                app.Release,
                app.VirtualPath,
                CustomErrors = app.CustomErrors.Select(c => new
                {
                    StatusCode = ((HttpStatusCode)c.StatusCode).ToString(),
                    c.Redirect
                }).ToArray()
            };
        }
        [PermissionFilter(Permission = FolderType.Application)]
        public ActionResult SubmitSettings(string application, bool? closeForm)
        {
            JsonResultData resultData = new JsonResultData();
            try
            {
                var app = dataContext.QueryApplication(application).First();
                app.Theme = Request.Form["Theme"];
                app.HostName = Request.Form["HostName"];
                app.Javascript = Request.Form["Javascript"];
                app.DisplayName = Request.Form["DisplayName"];
                app.VirtualPath = Request.Form["VirtualPath"];

                string release = Request.Form["Release"];

                if (StringExtensions.IsTrue(release))
                {
                    app.Release = true;
                }
                else
                {
                    app.Release = false;
                }
                app.Cms_CustomError.Load();
                while (app.Cms_CustomError.Count > 0)
                {
                    dataContext.DeleteObject(app.Cms_CustomError.First());
                }
                Dictionary<string, string>[] customErrors = Request.Form["CustomErrors"].DeserializeJSON<Dictionary<string, string>[]>();
                for (int i = 0; i < customErrors.Length; i++)
                {
                    var customError = Cms_CustomError.CreateCms_CustomError(customErrors[i]);
                    if (customError != null)
                    {
                        app.Cms_CustomError.Add(customError);
                    }
                }
                dataContext.SaveChanges();
                if (closeForm == false && resultData.success)
                {
                    resultData.closeForm = false;
                    resultData.data = GetApplicationSettings(application);
                }
            }
            catch (RuleViolationException ruleException)
            {
                ruleException.Issues.UpdateResultDataWithViolations(resultData);
                Everest.Library.HealthMonitor.HealthMonitoringLogging.LogError(ruleException);
            }
            return Json(resultData);
        }
        #endregion

        #region Export
        [PermissionFilter(Permission = FolderType.Application)]
        public ActionResult Export(string application, string packageName)
        {
            JsonResultData resultData = new JsonResultData() { closeForm = true };

            bool exportSiteElements = StringExtensions.IsTrue(Request.Form["SiteElements"]);
            bool exportContents = StringExtensions.IsTrue(Request.Form["Contents"]);

            if (StringExtensions.IsNullOrEmptyTrim(packageName))
            {
                packageName = application;
            }
            ApplicationService applicationService = UnityManager.Resolve<ApplicationService>();
            applicationService.Export(application, packageName, exportSiteElements, exportContents);

            return Json(resultData);

        }
        [PermissionFilter(Permission = FolderType.Application)]
        public ActionResult ExportTemplate(string application, string packageName)
        {
            JsonResultData resultData = new JsonResultData() { closeForm = true };

            if (StringExtensions.IsNullOrEmptyTrim(packageName))
            {
                packageName = application;
            }

            ApplicationService applicationService = UnityManager.Resolve<ApplicationService>();
            applicationService.ExportTemplate(application, packageName);

            return Json(resultData);
        }
        #endregion

        #region Import
        [PermissionFilter(Permission = FolderType.Application)]
        public ActionResult Import(string applicationName, string sitePackage)
        {
            JsonResultData resultData = new JsonResultData() { closeForm = true };

            bool renewId = StringExtensions.IsTrue(Request.Form["RenewId"]);

            ApplicationService applicationService = UnityManager.Resolve<ApplicationService>();
            applicationService.Import(applicationName, sitePackage, renewId);

            return Json(resultData);
        }

        [PermissionFilter(Permission = FolderType.Application)]
        public ActionResult ImportTemplate(string application, string templatePackage)
        {
            JsonResultData resultData = new JsonResultData() { closeForm = true };

            bool @override = StringExtensions.IsTrue(Request.Form["Override"]);

            ApplicationService applicationService = UnityManager.Resolve<ApplicationService>();
            applicationService.ImportTemplate(application, templatePackage, @override);

            return Json(resultData);
        }
        #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.