/*
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;
using Everest.Library.Mvc;
using Everest.Library.Extjs;
using Everest.Library.Data.Entity;
using Everest.Library.Json;
using Everest.Library.Extjs.Tree;
using Everest.Library.ExtensionMethod;
using Everest.Library.Scheduler;
using Everest.CmsServices.Services;
using Everest.CmsServices.Models;
using Everest.Library.Data.Rule;
namespace Everest.CmsServices.Controllers{
[PermissionFilter(Permission = FolderType.SearchSetting)]
public class SearchSettingController : CmsExtController
{
#region IStandardActions Members
public ActionResult GetList()
{
IEverestCmsDataContext dataContext = EverestCmsEntities.GetDataContext();
int start, limit;
EnsurePaging(out start, out limit);
string application = Request.Form["application"];
Expression<Func<Cms_SearchSetting, bool>> condition = s => s.aspnet_Applications.ApplicationName == application;
IQueryable<Cms_SearchSetting> query = dataContext.Cms_SearchSetting.Where(condition).OrderByDescending(s => s.Cms_Folder.FolderName);
query = OrderByRequest(query);
var queryResult = query.Select<Cms_SearchSetting, object>(s => new QueriedSearchSetting()
{
UUID = s.UUID,
FolderApplication = s.Cms_Folder.aspnet_Applications.ApplicationName,
FolderName = s.Cms_Folder.FolderName,
Url = s.Url,
Application = s.aspnet_Applications.ApplicationName
});
return Json(new ExtJsonReaderObject(queryResult.Skip(start).Take(limit).ToArray(), queryResult.Count()));
}
public ActionResult GetDetail(Guid uuid)
{
object jsonData = GetSearchSettingDetail(uuid);
return Json(new JsonResultData() { success = true, data = jsonData });
}
public object GetSearchSettingDetail(Guid uuid)
{
IEverestCmsDataContext dataContext = EverestCmsEntities.GetDataContext();
var searchSetting = dataContext.Cms_SearchSetting.Where(s => s.UUID == uuid)
.Select(s => new QueriedSearchSetting()
{
UUID = s.UUID,
FolderApplication = s.Cms_Folder.aspnet_Applications.ApplicationName,
FolderName = s.Cms_Folder.FolderName,
Url = s.Url,
Application = s.aspnet_Applications.ApplicationName
}).First();
return searchSetting;
}
public ActionResult Submit(bool add, bool? closeForm)
{
IEverestCmsDataContext dataContext = EverestCmsEntities.GetDataContext();
JsonResultData resultData = new JsonResultData();
Cms_SearchSetting searchSetting;
try
{
if (add)
{
searchSetting = new Cms_SearchSetting();
string application = Request.Form["application"];
searchSetting.aspnet_Applications = dataContext.QueryApplication(application).First();
dataContext.AddToCms_SearchSetting(searchSetting);
}
else
{
Guid uuid = new Guid(Request.Form["oldData.UUID"]);
searchSetting = dataContext.Cms_SearchSetting.Where(s => s.UUID == uuid).First();
}
UniqueName uniqueName = new UniqueName(Request.Form["Folder"]);
searchSetting.Cms_Folder = dataContext.QueryFolder(uniqueName.ApplicationName, uniqueName.ItemName).First();
searchSetting.Url = Request.Form["Url"];
dataContext.SaveChanges();
if (closeForm.Value == false && resultData.success)
{
resultData.closeForm = false;
resultData.data = GetSearchSettingDetail(searchSetting.UUID);
}
}
catch (RuleViolationException ruleException)
{
ruleException.Issues.UpdateResultDataWithViolations(resultData);
Everest.Library.HealthMonitor.HealthMonitoringLogging.LogError(ruleException);
}
return Json(resultData);
}
public ActionResult Delete(Guid[] uuid)
{
IEverestCmsDataContext dataContext = EverestCmsEntities.GetDataContext();
JsonResultData resultData = new JsonResultData() { success = true };
Expression<Func<Cms_SearchSetting, bool>> expression = EfUtility.BuildContainsExpression<Cms_SearchSetting, Guid>(r => r.UUID, uuid);
var searchSettings = dataContext.Cms_SearchSetting.Where(expression);
foreach (var item in searchSettings)
{
dataContext.DeleteObject(item);
}
dataContext.SaveChanges();
return Json(resultData);
}
#endregion
}
}
|