/*
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 Everest.Library.Data.Entity;
using Everest.Library.ExtensionMethod;
namespace Everest.CmsServices.Models{
public class DataRuleQuery
{
public int DataRuleId { get; set; }
public string DataName { get; set; }
public string ValueType { get; set; }
public string ValueRule { get; set; }
public int Order { get; set; }
public Guid? FolderUUID { get; set; }
public string OrderBy { get; set; }
public string TopCount { get; set; }
public bool? IncludeChildren { get; set; }
public int DynamicLinkingOrder { get; set; }
public string ReferencingContentId { get; set; }
public string PageIndex { get; set; }
public string PageSize { get; set; }
public string Caching { get; set; }
public string Folder
{
get
{
if (this.FolderUUID.HasValue)
{
var folderName = EverestCmsEntities.GetDataContext().QueryFolder(this.FolderUUID.Value)
.Select(f => new UniqueName() { ApplicationName = f.aspnet_Applications.ApplicationName, ItemName = f.FolderName }).First();
return folderName.ToString();
}
return string.Empty;
}
set
{
}
}
}
public static class DataRuleHelper
{
public static IEnumerable<DataRuleQuery> ToDataRuleQuery(this IEnumerable<Cms_DataRule> dataRules)
{
return dataRules.Select(d => new DataRuleQuery()
{
DataRuleId = d.DataRuleId,
DataName = d.DataName,
ValueType = ((DataRuleValueType)d.ValueType).ToString(),
ValueRule = d.ValueRule,
Order = d.Order,
FolderUUID = d.FolderUUIDFromReference,
OrderBy = d.OrderBy,
TopCount = d.TopCount,
IncludeChildren = d.IncludeChildren,
DynamicLinkingOrder = d.DynamicLinkingOrder,
ReferencingContentId = d.ReferencingContentId,
PageIndex = d.PageIndex,
PageSize = d.PageSize,
Caching = d.Caching
}).OrderBy(d => d.Order);
}
}
public partial class Cms_DataRule
{
public Cms_DataRule()
{
this.UUID = Guid.NewGuid();
}
public static Cms_DataRule CreateCms_DataRule(IEverestCmsDataContext dataContext, IDictionary<string, string> dic)
{
bool isBlank = dic.IsValueEmpty();
if (isBlank)
{
return null;
}
Cms_DataRule dataRule = new Cms_DataRule();
dataRule.UUID = Guid.NewGuid();
dataRule.DataName = dic["DataName"];
dataRule.ValueRule = dic["ValueRule"];
dataRule.OrderBy = dic["OrderBy"];
dataRule.ValueType = (int)(DataRuleValueType)Enum.Parse(typeof(DataRuleValueType), dic["ValueType"]);
if (!StringExtensions.IsNullOrEmptyTrim(dic["Folder"]))
{
UniqueName uniqueName = new UniqueName(dic["Folder"]);
dataRule.Cms_Folder = dataContext.QueryFolder(uniqueName.ApplicationName, uniqueName.ItemName, FolderType.TextContent, FolderType.BinaryContent).First();
}
dataRule.TopCount = dic["TopCount"];
dataRule.IncludeChildren = dic["IncludeChildren"].GetNullableBool();
if (!StringExtensions.IsNullOrEmptyTrim(dic["DynamicLinkingOrder"]))
{
dataRule.DynamicLinkingOrder = int.Parse(dic["DynamicLinkingOrder"]);
}
else
{
dataRule.DynamicLinkingOrder = 1;
}
dataRule.ReferencingContentId = dic["ReferencingContentId"];
dataRule.PageIndex = dic["PageIndex"];
dataRule.PageSize = dic["PageSize"];
dataRule.Caching = dic["Caching"];
return dataRule;
}
public Cms_DataRule Copy()
{
Cms_DataRule newDataRule = new Cms_DataRule();
newDataRule.DataName = this.DataName;
this.Cms_FolderReference.Load(this.Cms_Folder, this.EntityState);
newDataRule.Cms_Folder = this.Cms_Folder;
newDataRule.ValueRule = this.ValueRule;
newDataRule.ValueType = this.ValueType;
newDataRule.Order = this.Order;
newDataRule.OrderBy = this.OrderBy;
newDataRule.DynamicLinkingOrder = this.DynamicLinkingOrder;
newDataRule.ReferencingContentId = this.ReferencingContentId;
newDataRule.PageIndex = this.PageIndex;
newDataRule.PageSize = this.PageSize;
newDataRule.Caching = this.Caching;
return newDataRule;
}
/// <summary>
/// Gets or sets the folder UUID from reference.
/// </summary>
/// <value>The folder UUID from reference.</value>
public Guid? FolderUUIDFromReference
{
get
{
return this.Cms_FolderReference.EntityKey.GetKeyValue<Guid?>("UUID");
}
}
public TimeSpan CachingTimeSpan
{
get
{
if (StringExtensions.IsNullOrEmptyTrim(this.Caching))
{
return TimeSpan.MinValue;
}
if (Caching == "Max")
{
return TimeSpan.MaxValue;
}
return TimeSpan.Parse(this.Caching);
}
}
}
}
|