/*
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.Mvc;
using System.Linq.Expressions;
using Everest.Library.Mvc;
using Everest.Library.Extjs;
using Everest.Library.Extjs.Tree;
using Everest.CmsServices.Models;
using Everest.Library.ExtensionMethod;
namespace Everest.CmsServices.Controllers{
public class WebFormController : CmsExtController
{
private IEverestCmsDataContext dataContext = EverestCmsEntities.GetDataContext();
#region Standard actions
[PermissionFilter(Permission = FolderType.WebForm)]
public ActionResult GetList()
{
int start, limit;
this.EnsurePaging(out start, out limit);
string application = this.Request.Form["application"];
IQueryable<Cms_CustomerForm> query = dataContext.QueryWebForms(application);
query = this.OrderByRequest(query);
var queryResult = query.Select<Cms_CustomerForm, object>(frm => new
{
frm.UUID,
frm.FormId,
frm.FormName,
frm.PostDate,
Application = frm.aspnet_Applications.ApplicationName
});
return this.Json(new ExtJsonReaderObject(queryResult.Skip(start).Take(limit).ToArray(), queryResult.Count()));
}
[PermissionFilter(Permission = FolderType.WebForm)]
public ActionResult Delete(string[] UUID)
{
foreach (var requesId in UUID)
{
var form = this.QueryFormByUUID(requesId);
if (form != null)
{
if (form.Cms_CustomerFormValues.Count > 0)
{
Cms_CustomerFormValues item = null;
do
{
item = form.Cms_CustomerFormValues.FirstOrDefault();
if (item != null)
{
form.Cms_CustomerFormValues.Remove(item);
dataContext.DeleteObject(item);
}
}
while (item != null);
}
dataContext.DeleteObject(form);
dataContext.SaveChanges();
}
}
return this.Json(new JsonResultData() { success = true });
}
private Cms_CustomerForm QueryFormByUUID(string formUUID)
{
if (StringExtensions.IsNullOrEmptyTrim(formUUID))
return null;
Guid uid = new Guid(formUUID);
Cms_CustomerForm form = (from f in dataContext.Cms_CustomerForm
where f.UUID == uid
select f).First();
return form;
}
private object GetFormDetailData(string formUUID)
{
if (StringExtensions.IsNullOrEmptyTrim(formUUID))
return null;
Guid uid = new Guid(formUUID);
var formQuery = from form in dataContext.Cms_CustomerForm
where form.UUID == uid
select new
{
form.UUID,
form.FormId,
form.CustomStyles,
form.FormName
};
return formQuery.First();
}
[PermissionFilter(Permission = FolderType.WebForm)]
public ActionResult GetDetail(string UUID, string application)
{
return Json(new JsonResultData()
{
data = this.GetFormDetailData(UUID)
});
}
[PermissionFilter(Permission = FolderType.WebForm)]
public ActionResult Submit(bool add, bool? closeForm, string CustomStyles, string FormName)
{
JsonResultData resultData = new JsonResultData();
Cms_CustomerForm form = null;
try
{
if (!add)
{
form = this.QueryFormByUUID(this.Request.Form["oldData.UUID"]);
if (form != null)
{
form.CustomStyles = CustomStyles;
form.FormName = FormName;
dataContext.SaveChanges();
}
}
if (closeForm.Value == false && resultData.success == true)
{
resultData.closeForm = false;
if (form != null)
resultData.data = this.GetFormDetailData(form.UUID.ToString());
}
}
catch (Exception ex)
{
resultData.AddError("Title", ex.Message);
Everest.Library.HealthMonitor.HealthMonitoringLogging.LogError(ex);
}
return Json(resultData);
}
#endregion
#region Relations
public ActionResult UsedBy(string UUID)
{
IEverestCmsDataContext dataContext = EverestCmsEntities.GetDataContext();
IList<Dictionary<string, object>> treeNodes = new List<Dictionary<string, object>>();
#region Used in Pages
var pageNodes = new TreeNode();
treeNodes.Add(pageNodes.Attributes);
pageNodes.Text = Resources.TreeNode_Page;
pageNodes.IconCls = FolderType.Page.ToString();
pageNodes.Leaf = false;
pageNodes.Expanded = true;
var pages = dataContext.QueryPagesByWebForm(UUID)
.Select(p => new { p.UUID, p.aspnet_Applications.ApplicationName, p.PageName });
pageNodes.children = new List<IDictionary<string, object>>();
foreach (var page in pages)
{
var pageNode = new TreeNode();
pageNodes.children.Add(pageNode.Attributes);
pageNode.Text = new UniqueName(page.ApplicationName, page.PageName).ToString();
pageNode.Attributes.Add("uuid", page.UUID);
pageNode.IconCls = "PageNode";
pageNode.Attributes.Add("dataUrl", "Kooboo_Page/UsedBy");
}
#endregion
return Json(treeNodes);
}
#endregion
}
}
|