/*
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.Web;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;
using Everest.CmsServices.Models;
namespace Everest.CmsServices.MvcHelper{
public static class ContentExtension
{
private static CmsContext CmsContext
{
get
{
return HttpContext.Current.GetCmsContext();
}
}
#region DataTypeConvertor
/// <summary>
/// Toes the list.
/// </summary>
/// <param name="contents">The contents.</param>
/// <returns></returns>
public static IEnumerable<IDictionary<string, object>> ToList(object contents)
{
return (IEnumerable<IDictionary<string, object>>)contents;
}
/// <summary>
/// Toes the content.
/// </summary>
/// <param name="content">The content.</param>
/// <returns></returns>
public static IDictionary<string, object> ToContent(object content)
{
return (IDictionary<string, object>)content;
}
#endregion
#region Get SubContent
/// <summary>
/// Gets the sub contents.
/// </summary>
/// <param name="parentContent">Content of the parent.</param>
/// <param name="schemaName">Name of the schema of subcontent.</param>
/// <param name="queryStatement">The query statement.For example: Title={Title}</param>
/// <param name="orderBy">The order by field. For example: Title DESC</param>
/// <param name="queryValues">The query values. The values for Query Statment parameters</param>
/// <param name="startIndex">The start index.starts from 1</param>
/// <param name="pageSize">Size of the page.</param>
/// <param name="cacheTime">The cache time.</param>
/// <returns></returns>
public static IEnumerable<IDictionary<string, object>> GetSubContents(this IDictionary<string, object> parentContent, string schemaName
, string queryStatement, string orderBy, NameValueCollection queryValues, int startIndex, int pageSize, TimeSpan? cacheTime)
{
var contentUUID = (Guid)parentContent["UUID"];
return CmsContext.ContentService.GetSubContents(contentUUID, schemaName, queryStatement, orderBy, queryValues, startIndex, pageSize, cacheTime);
}
/// <summary>
/// Gets the sub contents.
/// </summary>
/// <param name="parentContent">Content of the parent.</param>
/// <param name="schemaName">Name of the schema of subcontent.</param>
/// <returns></returns>
public static IEnumerable<IDictionary<string, object>> GetSubContents(this IDictionary<string, object> parentContent, string schemaName)
{
var contentUUID = (Guid)parentContent["UUID"];
return CmsContext.ContentService.GetSubContents(contentUUID, schemaName);
}
/// <summary>
/// Gets the sub content count.
/// </summary>
/// <param name="parentContent">Content of the parent.</param>
/// <param name="schemaName">Name of the schema of subcontent.</param>
/// <param name="queryStatement">The query statement.For example: Title={Title}</param>
/// <param name="queryValues">The query values. The values for Query Statment parameters</param>
/// <param name="cacheTime">The cache time.</param>
/// <returns></returns>
public static int GetSubContentCount(this IDictionary<string, object> parentContent, string schemaName, string queryStatement, NameValueCollection queryValues, TimeSpan? cacheTime)
{
var contentUUID = (Guid)parentContent["UUID"];
return CmsContext.ContentService.GetSubContentCount(contentUUID, schemaName, queryStatement, queryValues, null);
}
/// <summary>
/// Gets the sub content count.
/// </summary>
/// <param name="parentContent">Content of the parent.</param>
/// <param name="schemaName">Name of the schema of subcontent.</param>
/// <returns></returns>
public static int GetSubContentCount(this IDictionary<string, object> parentContent, string schemaName)
{
var contentUUID = (Guid)parentContent["UUID"];
return CmsContext.ContentService.GetSubContentCount(contentUUID, schemaName);
}
#endregion
#region Content data extension
#region GetContentsByCategory
/// <summary>
/// Gets the contents by category and schema.
/// </summary>
/// <param name="category">The content of category.</param>
/// <param name="schemaName">The content schema to be returnd. Not the category schema</param>
/// <param name="queryStatement">The query statement.For example: Title={Title}</param>
/// <param name="orderBy">The order by field. For example: Title DESC</param>
/// <param name="queryValues">The query values. The values for Query Statment parameters</param>
/// <param name="startIndex">The start index.starts from 1</param>
/// <param name="pageSize">Size of the page.</param>
/// <param name="cacheTime">The cache time.</param>
/// <returns></returns>
public static IEnumerable<IDictionary<string, object>> GetContentsByCategoryAndSchema(this IDictionary<string, object> category
, string schemaName, string queryStatement, string orderBy, NameValueCollection queryValues, int startIndex, int pageSize
, TimeSpan? cacheTime)
{
var categoryOriginalUUID = (Guid)category["OriginalUUID"];
return CmsContext.ContentService.GetContentsByCategoryAndSchema(categoryOriginalUUID, schemaName
, queryStatement, orderBy, queryValues, startIndex, pageSize, cacheTime);
}
/// <summary>
/// Gets the content count by category and schema.
/// </summary>
/// <param name="category">The content of category.</param>
/// <param name="schemaName">The content schema to be returnd. Not the category schema</param>
/// <param name="queryStatement">The query statement.For example: Title={Title}</param>
/// <param name="queryValues">The query values. The values for Query Statment parameters</param>
/// <param name="cacheTime">The cache time.</param>
/// <returns></returns>
public static int GetContentCountByCategoryAndSchema(this IDictionary<string, object> category, string schemaName, string queryStatement
, NameValueCollection queryValues, TimeSpan? cacheTime)
{
var categoryOriginalUUID = (Guid)category["OriginalUUID"];
return CmsContext.ContentService.GetContentCountByCategoryAndSchema(categoryOriginalUUID, schemaName, queryStatement, queryValues, cacheTime);
}
/// <summary>
/// Gets the contents by category and folder.
/// </summary>
/// <param name="category">The content of category.</param>
/// <param name="folderName">Name of the folder.</param>
/// <param name="queryStatement">The query statement.For example: Title={Title}</param>
/// <param name="orderBy">The order by field. For example: Title DESC</param>
/// <param name="queryValues">The query values. The values for Query Statment parameters</param>
/// <param name="startIndex">The start index. starts from 1</param>
/// <param name="pageSize">Size of the page.</param>
/// <param name="cacheTime">The cache time.</param>
/// <returns></returns>
public static IEnumerable<IDictionary<string, object>> GetContentsByCategoryAndFolder(this IDictionary<string, object> category, string folderName,
string queryStatement, string orderBy, NameValueCollection queryValues, int startIndex, int pageSize, TimeSpan? cacheTime)
{
var categoryOriginalUUID = (Guid)category["OriginalUUID"];
return CmsContext.ContentService.GetContentsByCategoryAndFolder(categoryOriginalUUID, folderName
, queryStatement, orderBy, queryValues, startIndex, pageSize, cacheTime);
}
/// <summary>
/// Gets the contents by category and folder.
/// </summary>
/// <param name="category">The category.</param>
/// <param name="folderName">Name of the folder.</param>
/// <returns></returns>
public static IEnumerable<IDictionary<string, object>> GetContentsByCategoryAndFolder(this IDictionary<string, object> category, string folderName)
{
var categoryOriginalUUID = (Guid)category["OriginalUUID"];
return CmsContext.ContentService.GetContentsByCategoryAndFolder(categoryOriginalUUID, folderName);
}
/// <summary>
/// Gets the content count by category and folder.
/// </summary>
/// <param name="category">The category.</param>
/// <param name="folderName">Name of the folder.</param>
/// <param name="queryStatement">The query statement.For example: Title={Title}</param>
/// <param name="queryValues">The query values. The values for Query Statment parameters</param>
/// <param name="cacheTime">The cache time.</param>
/// <returns></returns>
public static int GetContentCountByCategoryAndFolder(this IDictionary<string, object> category, string folderName, string queryStatement,
NameValueCollection queryValues, TimeSpan? cacheTime)
{
var categoryOriginalUUID = (Guid)category["OriginalUUID"];
return CmsContext.ContentService.GetContentCountByCategoryAndFolder(categoryOriginalUUID, folderName,
queryStatement, queryValues, cacheTime);
}
/// <summary>
/// Gets the content count by category and folder.
/// </summary>
/// <param name="category">The category.</param>
/// <param name="folderName">Name of the folder.</param>
/// <returns></returns>
public static int GetContentCountByCategoryAndFolder(this IDictionary<string, object> category, string folderName)
{
var categoryOriginalUUID = (Guid)category["OriginalUUID"];
return CmsContext.ContentService.GetContentCountByCategoryAndFolder(categoryOriginalUUID, folderName);
}
#endregion
#region GetCategoriesByContent
/// <summary>
/// Gets the categories by content and schema.
/// </summary>
/// <param name="content">The content.</param>
/// <param name="schemaName">The cateogry schema of object returned.</param>
/// <param name="queryStatement">The query statement.For example: Title={Title}</param>
/// <param name="orderBy">The order by field. For example: Title DESC</param>
/// <param name="queryValues">The query values. The values for Query Statment parameters</param>
/// <param name="startIndex">The start index.starts from 1</param>
/// <param name="pageSize">Size of the page.</param>
/// <param name="cacheTime">The cache time.</param>
/// <returns></returns>
public static IEnumerable<IDictionary<string, object>> GetCategoriesByContentAndSchema(this IDictionary<string, object> content, string schemaName,
string queryStatement, string orderBy, NameValueCollection queryValues, int startIndex, int pageSize, TimeSpan? cacheTime)
{
var contentUUID = (Guid)content["UUID"];
return CmsContext.ContentService.GetCategoriesByContentAndSchema(contentUUID, schemaName, queryStatement, orderBy,
queryValues, startIndex, pageSize, cacheTime);
}
/// <summary>
/// Gets the categories by content and schema.
/// </summary>
/// <param name="content">The content.</param>
/// <param name="schemaName">Name of the schema.</param>
/// <returns></returns>
public static IEnumerable<IDictionary<string, object>> GetCategoriesByContentAndSchema(this IDictionary<string, object> content, string schemaName)
{
var contentUUID = (Guid)content["UUID"];
return CmsContext.ContentService.GetCategoriesByContentAndSchema(contentUUID, schemaName);
}
/// <summary>
/// Gets the category count by content and schema.
/// </summary>
/// <param name="content">The content.</param>
/// <param name="schemaName">The cateogry schema of object returned.</param>
/// <param name="queryStatement">The query statement.For example: Title={Title}</param>
/// <param name="queryValues">The query values. The values for Query Statment parameters</param>
/// <param name="cacheTime">The cache time.</param>
/// <returns></returns>
public static int GetCategoryCountByContentAndSchema(this IDictionary<string, object> content, string schemaName, string queryStatement,
NameValueCollection queryValues, TimeSpan? cacheTime)
{
var contentUUID = (Guid)content["UUID"];
return CmsContext.ContentService.GetCategoryCountByContentAndSchema(contentUUID, schemaName, queryStatement, queryValues, cacheTime);
}
/// <summary>
/// Gets the category count by content and schema.
/// </summary>
/// <param name="content">The content.</param>
/// <param name="schemaName">Name of the schema.</param>
/// <returns></returns>
public static int GetCategoryCountByContentAndSchema(this IDictionary<string, object> content, string schemaName)
{
var contentUUID = (Guid)content["UUID"];
return CmsContext.ContentService.GetCategoryCountByContentAndSchema(contentUUID, schemaName);
}
/// <summary>
/// Gets the categories by content and folder.
/// </summary>
/// <param name="content">The content.</param>
/// <param name="folderName">Name of the folder of category content.</param>
/// <param name="queryStatement">The query statement.For example: Title={Title}</param>
/// <param name="orderBy">The order by field. For example: Title DESC</param>
/// <param name="queryValues">The query values. The values for Query Statment parameters</param>
/// <param name="startIndex">The start index.starts from 1</param>
/// <param name="pageSize">Size of the page.</param>
/// <param name="cacheTime">The cache time.</param>
/// <returns></returns>
public static IEnumerable<IDictionary<string, object>> GetCategoriesByContentAndFolder(this IDictionary<string, object> content, string folderName,
string queryStatement, string orderBy, NameValueCollection queryValues, int startIndex, int pageSize, TimeSpan? cacheTime)
{
var contentUUID = (Guid)content["UUID"];
return CmsContext.ContentService.GetCategoriesByContentAndFolder(contentUUID, folderName, queryStatement,
orderBy, queryValues, startIndex, pageSize, cacheTime);
}
/// <summary>
/// Gets the categories by content and folder.
/// </summary>
/// <param name="content">The content.</param>
/// <param name="folderName">Name of the folder.</param>
/// <returns></returns>
public static IEnumerable<IDictionary<string, object>> GetCategoriesByContentAndFolder(this IDictionary<string, object> content, string folderName)
{
var contentUUID = (Guid)content["UUID"];
return CmsContext.ContentService.GetCategoriesByContentAndFolder(contentUUID, folderName);
}
/// <summary>
/// Gets the category count by content and folder.
/// </summary>
/// <param name="content">The content.</param>
/// <param name="folderName">Name of the folder of category content.</param>
/// <param name="queryStatement">The query statement.For example: Title={Title}</param>
/// <param name="queryValues">The query values. The values for Query Statment parameters</param>
/// <returns></returns>
public static int GetCategoryCountByContentAndFolder(this IDictionary<string, object> content, string folderName, string queryStatement,
NameValueCollection queryValues, TimeSpan? cacheTime)
{
var contentUUID = (Guid)content["UUID"];
return CmsContext.ContentService.GetCategoryCountByContentAndFolder(contentUUID, folderName, queryStatement, queryValues, cacheTime);
}
/// <summary>
/// Gets the category count by content and folder.
/// </summary>
/// <param name="content">The content.</param>
/// <param name="folderName">Name of the folder.</param>
/// <returns></returns>
public static int GetCategoryCountByContentAndFolder(this IDictionary<string, object> content, string folderName)
{
var contentUUID = (Guid)content["UUID"];
return CmsContext.ContentService.GetCategoryCountByContentAndFolder(contentUUID, folderName);
}
#endregion
#endregion
}
}
|