/*
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.Linq;
using System.Text;
using System.Web;
using System.Collections.Generic;
using System.Collections.Specialized;
using Everest.Library;
using Everest.Library.Data.Entity;
using Everest.CmsServices.Exceptions;
using Everest.CmsServices.Models;
using Everest.CmsServices.Providers;
using Everest.CmsServices.Services;
using Everest.Library.ExtensionMethod;
namespace Everest.CmsServices.MvcHelper{
public class ContentService
{
private QueryType queryType = QueryType.Published;
/// <summary>
/// Sets the type of the query.
/// </summary>
/// <param name="queryType">Type of the query.</param>
public ContentService SetQueryType(QueryType queryType)
{
this.queryType = queryType;
return this;
}
#region .ctor
const int DefaultQuerySize = 1000;
public ContentService(IEverestCmsDataContext dataContext, IContentProvider contentProvider, aspnet_Applications application)
{
DataContext = dataContext;
ContentProvider = contentProvider;
Application = application;
}
public ContentService(string app)
: this(EverestCmsEntities.GetDataContext(), UnityManager.Resolve<IContentProvider>(), CachedData.GetApplication(app))
{
}
private IEverestCmsDataContext DataContext
{
get;
set;
}
private IContentProvider ContentProvider
{
get;
set;
}
private aspnet_Applications Application
{
get;
set;
}
#endregion
#region ContentFiles
/// <summary>
/// Gets the attachments, includes both "file included" and "binary schema" defined in the text schema. Files in "file includes" only has value in the field of "FileUrl". Files in Binary Schema also has additional values in the fields of "BinaryContentUUID" and "BinaryContentTitle".
/// </summary>
/// <param name="contentId">The ContentId</param>
/// <returns></returns>
public IEnumerable<FileInContent> GetAttachments(int contentId)
{
List<FileInContent> attachments = new List<FileInContent>();
var contentFilesQuery = from f in DataContext.Cms_ContentFile
where f.TextContent.ContentId == contentId && f.BinaryContent == null
select f;
foreach (var item in contentFilesQuery)
{
attachments.Add(new FileInContent() { FilePath = item.FilePath, FileUrl = item.FileUrl });
}
var binaryContentQuery = DataContext.Cms_ContentFile.Where(f => f.TextContent.ContentId == contentId && f.BinaryContent != null)
.Select(f => new
{
f.BinaryContent.Cms_BinaryContent,
f.BinaryContent.Title
});
foreach (var item in binaryContentQuery)
{
attachments.Add(new FileInContent() { FilePath = item.Cms_BinaryContent.FilePath, FileUrl = item.Cms_BinaryContent.FileUrl, BinaryContentUUID = item.Cms_BinaryContent.ContentUUID, BinaryContentTitle = item.Title });
}
return attachments;
}
#endregion
#region Get Schema & folder
/// <summary>
/// return the schma object based on schema name and current application context. Can be used for example when query or update data based on schema name.
/// </summary>
/// <param name="schemaName">Name of the schema.</param>
/// <returns></returns>
public Cms_Schema GetSchema(string schemaName)
{
var schema = CachedData.GetSchema(Application.ApplicationName, schemaName);
if (schema == null)
{
throw new SchemaNotFoundException(Application.ApplicationName, schemaName);
}
return schema;
}
/// <summary>
/// return the folder object based folder name and current application context, used for data access based on folder.
/// </summary>
/// <param name="folderName">Name of the folder.</param>
/// <returns></returns>
public Cms_Folder GetFolder(string folderName)
{
var folder = CachedData.GetFolder(Application.ApplicationName, folderName);
if (folder == null)
{
throw new FolderNotFoundException(Application.ApplicationName, folderName);
}
return folder;
}
/// <summary>
/// Get the orginal content UUID in the root of folder relation.
/// </summary>
/// <param name="contentId"></param>
/// <returns></returns>
private Guid? GetContentOriginalUUID(int contentId)
{
return DataContext.QueryContent(contentId).Select(c => c.OriginalUUID).FirstOrDefault();
}
/// <summary>
/// return content UUID based on content ID
/// </summary>
/// <param name="contentId"></param>
/// <returns></returns>
private Guid? GetContentUUID(int contentId)
{
return DataContext.QueryContent(contentId).Select(c => c.OriginalUUID).FirstOrDefault();
}
#endregion
#region AddContent
/// <summary>
/// Add a content
/// </summary>
/// <param name="folderName">Name of the folder.</param>
/// <param name="userName">In the content template, userName can be accessed using User.Identity.Name</param>
/// <param name="values">NameValueCollection with the same key name as in the folder schema definition, can be Request.Form</param>
/// <param name="files">Can be ViewContext.HttpContext.Request.Files or null</param>
/// <param name="categories">The categories.</param>
/// <returns></returns>
public Cms_Content AddContent(string folderName, string userName, NameValueCollection values, HttpFileCollectionBase files, params Guid[] categories)
{
return this.AddContent(folderName, userName, values, files, true, categories);
}
/// <summary>
/// Add a content
/// </summary>
/// <param name="folderName">Name of the folder.</param>
/// <param name="userName">In the content template, userName can be accessed using User.Identity.Name</param>
/// <param name="values">NameValueCollection with the same key name as in the folder schema definition, can be Request.Form</param>
/// <param name="files">Can be ViewContext.HttpContext.Request.Files or null</param>
/// <param name="published">if set to <c>true</c> [published].</param>
/// <param name="categories">The categories.</param>
/// <returns></returns>
public Cms_Content AddContent(string folderName, string userName, NameValueCollection values, HttpFileCollectionBase files, bool published, params Guid[] categories)
{
var folder = GetFolder(folderName);
var schema = CachedData.GetSchemaByFolder(folder.UUID);
NameValueCollection nameValues = new NameValueCollection(values);
nameValues["folderUUID"] = folder.UUID.ToString();
nameValues["SchemaUUID"] = schema.UUID.ToString();
//nameValues["application"] = Application.ApplicationName;
nameValues["Published"] = published.ToString();
if (categories != null && categories.Length > 0)
{
nameValues["ReferenceContents"] = string.Join(",", categories.Select(g => g.ToString()).ToArray());
}
var content = UnityManager.Resolve<TextContentService>().AddContent(nameValues, userName, files);
return content;
}
/// <summary>
/// Add a subcontent.Subcontent schema is defined in the "Child schema" at the Text Schema definition page.
/// </summary>
/// <param name="parentUUID">The parent content UUID.</param>
/// <param name="schemaName">Schema name of current Subcontent schema</param>
/// <param name="userName">In the content template, userName can be accessed using User.Identity.Name</param>
/// <param name="values">NameValueCollection with the same key name as in the folder schema definition, can be Request.Form</param>
/// <param name="files">Can be ViewContext.HttpContext.Request.Files or null</param>
/// <param name="categories">The categories.</param>
/// <returns></returns>
public Cms_Content AddSubContent(Guid parentUUID, string schemaName, string userName, NameValueCollection values, HttpFileCollectionBase files, params Guid[] categories)
{
return this.AddSubContent(parentUUID, schemaName, userName, values, files, true, categories);
}
/// <summary>
/// Add a subcontent.Subcontent schema is defined in the "Child schema" at the Text Schema definition page.
/// </summary>
/// <param name="parentUUID">The parent content UUID.</param>
/// <param name="schemaName">Schema name of current Subcontent schema</param>
/// <param name="userName">In the content template, userName can be accessed using User.Identity.Name</param>
/// <param name="values">NameValueCollection with the same key name as in the folder schema definition, can be Request.Form</param>
/// <param name="files">Can be ViewContext.HttpContext.Request.Files or null</param>
/// <param name="published">if set to <c>true</c> [published].</param>
/// <param name="categories">The categories.</param>
/// <returns></returns>
public Cms_Content AddSubContent(Guid parentUUID, string schemaName, string userName, NameValueCollection values, HttpFileCollectionBase files, bool published, params Guid[] categories)
{
var schema = GetSchema(schemaName);
NameValueCollection nameValues = new NameValueCollection(values);
nameValues["ParentUUID"] = parentUUID.ToString();
nameValues["schemaUUID"] = schema.UUID.ToString();
nameValues["Published"] = published.ToString();
if (categories != null && categories.Length > 0)
{
nameValues["ReferenceContents"] = string.Join(",", categories.Select(g => g.ToString()).ToArray());
}
var content = UnityManager.Resolve<TextContentService>().AddContent(nameValues, userName, files);
return content;
}
/// <summary>
/// Add a subcontent.Subcontent schema is defined in the "Child schema" at the Text Schema definition page.
/// </summary>
/// <param name="parentId">The parent contentId.</param>
/// <param name="schemaName">Schema name of current Subcontent schema</param>
/// <param name="userName">In the content template, userName can be accessed using User.Identity.Name</param>
/// <param name="values">NameValueCollection with the same key name as in the folder schema definition, can be Request.Form</param>
/// <param name="files">Can be ViewContext.HttpContext.Request.Files or null</param>
/// <param name="categories">The categories.</param>
/// <returns></returns>
public Cms_Content AddSubContent(int parentId, string schemaName, string userName, NameValueCollection values, HttpFileCollectionBase files, params Guid[] categories)
{
return this.AddSubContent(parentId, schemaName, userName, values, files, true, categories);
}
/// <summary>
/// Add a subcontent.Subcontent schema is defined in the "Child schema" at the Text Schema definition page.
/// </summary>
/// <param name="parentId">The parent contentId.</param>
/// <param name="schemaName">Schema name of current Subcontent schema</param>
/// <param name="userName">In the content template, userName can be accessed using User.Identity.Name</param>
/// <param name="values">NameValueCollection with the same key name as in the folder schema definition, can be Request.Form</param>
/// <param name="files">Can be ViewContext.HttpContext.Request.Files or null</param>
/// <param name="published">if set to <c>true</c> [published].</param>
/// <param name="categories">The categories.</param>
/// <returns></returns>
public Cms_Content AddSubContent(int parentId, string schemaName, string userName, NameValueCollection values, HttpFileCollectionBase files, bool published, params Guid[] categories)
{
var content = DataContext.QueryContent(parentId).First();
return this.AddSubContent(content.UUID, schemaName, userName, values, files, published, categories);
}
/// <summary>
/// Adds the content of the binary.
/// </summary>
/// <param name="folderName">Name of the folder.</param>
/// <param name="userName">Name of the user.</param>
/// <param name="values">The values.</param>
/// <param name="file">The file.</param>
/// <param name="published">if set to <c>true</c> [published].</param>
/// <returns></returns>
public Cms_Content AddBinaryContent(string folderName, string userName, NameValueCollection values, HttpPostedFileBase file, bool published)
{
if (file == null)
{
throw new ArgumentNullException("file");
}
var folder = GetFolder(folderName);
if (folder == null)
{
throw new ArgumentException("folderName");
}
values["folderUUID"] = folder.UUID.ToString();
values["Published"] = published.ToString();
return UnityManager.Resolve<BinaryContentService>().AddBinaryContent(values, userName, file.FileName, file.InputStream);
}
#endregion
#region UpdateContent
/// <summary>
/// Updates the content.
/// </summary>
/// <param name="contentUUID">The content uuid.</param>
/// <param name="values">NameValueCollection with the same key name as in the folder schema definition, can be Request.Form</param>
/// <param name="userName">In the content template, userName can be accessed using User.Identity.Name</param>
/// <param name="files">Can be ViewContext.HttpContext.Request.Files or null</param>
/// <param name="categories">The categories.</param>
/// <returns></returns>
public Cms_Content UpdateContent(Guid contentUUID, NameValueCollection values, string userName, HttpFileCollectionBase files, params Guid[] categories)
{
return this.UpdateContent(contentUUID, values, userName, files, true, categories);
}
/// <summary>
/// Updates the content.
/// </summary>
/// <param name="contentUUID">The content uuid.</param>
/// <param name="values">NameValueCollection with the same key name as in the folder schema definition, can be Request.Form</param>
/// <param name="userName">In the content template, userName can be accessed using User.Identity.Name</param>
/// <param name="files">Can be ViewContext.HttpContext.Request.Files or null</param>
/// <param name="published">if set to <c>true</c> [published].</param>
/// <param name="categories">The categories.</param>
/// <returns></returns>
public Cms_Content UpdateContent(Guid contentUUID, NameValueCollection values, string userName, HttpFileCollectionBase files, bool published, params Guid[] categories)
{
NameValueCollection nameValues = new NameValueCollection(values);
if (categories != null && categories.Length > 0)
{
nameValues["ReferenceContents"] = string.Join(",", categories.Select(g => g.ToString()).ToArray());
}
nameValues["Published"] = published.ToString();
return UnityManager.Resolve<TextContentService>().UpdateContent(contentUUID, nameValues, userName, files, false);
}
/// <summary>
/// Updates the content.
/// </summary>
/// <param name="contentId">The content id.</param>
/// <param name="values">NameValueCollection with the same key name as in the folder schema definition, can be Request.Form</param>
/// <param name="userName">In the content template, userName can be accessed using User.Identity.Name</param>
/// <param name="files">Can be ViewContext.HttpContext.Request.Files or null</param>
/// <param name="categories">The categories.</param>
/// <returns></returns>
public Cms_Content UpdateContent(int contentId, NameValueCollection values, string userName, HttpFileCollectionBase files, params Guid[] categories)
{
return this.UpdateContent(contentId, values, userName, files, true, categories);
}
/// <summary>
/// Updates the content.
/// </summary>
/// <param name="contentId">The content id.</param>
/// <param name="values">NameValueCollection with the same key name as in the folder schema definition, can be Request.Form</param>
/// <param name="userName">In the content template, userName can be accessed using User.Identity.Name</param>
/// <param name="files">Can be ViewContext.HttpContext.Request.Files or null</param>
/// <param name="published">if set to <c>true</c> [published].</param>
/// <param name="categories">The categories.</param>
/// <returns></returns>
public Cms_Content UpdateContent(int contentId, NameValueCollection values, string userName, HttpFileCollectionBase files, bool published, params Guid[] categories)
{
NameValueCollection nameValues = new NameValueCollection(values);
if (categories != null && categories.Length > 0)
{
nameValues["ReferenceContents"] = string.Join(",", categories.Select(g => g.ToString()).ToArray());
}
nameValues["Published"] = published.ToString();
return UnityManager.Resolve<TextContentService>().UpdateContent(contentId, nameValues, userName, files, false);
}
#endregion
#region DeleteContent
/// <summary>
/// Delete the content.
/// </summary>
/// <param name="contentUUID">the content uuid.</param>
/// <param name="userName">the user name</param>
/// <returns>delete result</returns>
public bool DeleteContent(Guid contentUUID, string userName)
{
return UnityManager.Resolve<TextContentService>().Delete(contentUUID, userName);
}
/// <summary>
/// Delete the content.
/// </summary>
/// <param name="contentId">the content id.</param>
/// <param name="userName">the user name</param>
/// <returns>delete result</returns>
public bool DeleteContent(int contentId, string userName)
{
return UnityManager.Resolve<TextContentService>().Delete(contentId, userName);
}
#endregion
#region Get Content
/// <summary>
/// Gets the content.
/// </summary>
/// <param name="schema">The schema.</param>
/// <param name="queryStatement">The query statement.For example: Title={Title}</param>
/// <param name="parameters">The parameters.</param>
/// <returns></returns>
private IDictionary<string, object> GetContent(Cms_Schema schema, string queryStatement, NameValueCollection parameters, TimeSpan? cacheTime)
{
return ContentProvider.TextContentQuerier.SetQueryType(this.queryType).QueryContent(DataContext, schema, queryStatement, "", parameters.ToDictionary(), cacheTime);
}
/// <summary>
/// Gets the content by ID
/// </summary>
/// <param name="contentId">The contentId.</param>
/// <returns></returns>
public IDictionary<string, object> GetContentById(int contentId, TimeSpan? cacheTime)
{
var content = DataContext.QueryContent(contentId).FirstOrDefault();
if (content == null)
{
return null;
}
string queryStatement = "ContentId={ContentId}";
NameValueCollection na = new NameValueCollection();
na.Add("ContentId", contentId.ToString());
content.Cms_SchemaReference.Load(content.Cms_Schema, content.EntityState);
return GetContent(content.Cms_Schema, queryStatement, na, cacheTime);
}
/// <summary>
/// Gets the content by content UUID.
/// </summary>
/// <param name="contentUUID">The content UUID.</param>
/// <returns></returns>
public IDictionary<string, object> GetContentByUUID(Guid contentUUID, TimeSpan? cacheTime)
{
var content = DataContext.QueryContent(contentUUID).FirstOrDefault();
if (content == null)
{
return null;
}
string queryStatement = "ContentUUID={ContentUUID}";
NameValueCollection na = new NameValueCollection();
na.Add("ContentUUID", contentUUID.ToString());
content.Cms_SchemaReference.Load(content.Cms_Schema, content.EntityState);
return GetContent(content.Cms_Schema, queryStatement, na, cacheTime);
}
/// <summary>
/// Gets the content by user key.
/// </summary>
/// <param name="userKey">The UserKey</param>
/// <returns></returns>
public IDictionary<string, object> GetContentByUserKey(string userKey, TimeSpan? cacheTime)
{
var baseApp = this.Application;
Cms_Content content;
//If did not find the userkey in current application, try to get from base applcation until root.
// this is only used to query the schema information.
do
{
content = DataContext.QueryContent(baseApp.ApplicationName, userKey).FirstOrDefault();
if (content == null)
{
if (!StringExtensions.IsNullOrEmptyTrim(baseApp.BaseApplication))
{
baseApp = CachedData.GetApplication(baseApp.BaseApplication);
}
else
{
baseApp = null;
}
}
}
while (content == null && baseApp != null);
if (content == null)
{
return null;
}
string queryStatement = "ApplicationId={ApplicationId} AND UserKey={UserKey}";
NameValueCollection na = new NameValueCollection();
na.Add("UserKey", userKey.ToString());
na.Add("ApplicationId", baseApp.ApplicationId.ToString());
content.Cms_SchemaReference.Load(content.Cms_Schema, content.EntityState);
return GetContent(content.Cms_Schema, queryStatement, na, cacheTime);
}
#endregion
#region Get Contents
/// <summary>
/// Gets the contents from one folder
/// </summary>
/// <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, can be null</param>
/// <returns></returns>
public IEnumerable<IDictionary<string, object>> GetContentsByFolder(string folderName, string queryStatement, string orderBy,
NameValueCollection queryValues, int startIndex, int pageSize, TimeSpan? cacheTime)
{
var folder = GetFolder(folderName);
return ContentProvider.TextContentQuerier.SetQueryType(this.queryType).QueryContents(DataContext, queryStatement, orderBy, queryValues.ToDictionary(), folder
, folder.GetBaseFoldersRecusive(), startIndex, pageSize, cacheTime);
}
/// <summary>
/// Gets the contents from one folder.Default return records count defined in DefaultQuerySize, default is 1000
/// </summary>
/// <param name="folderName">Folder name</param>
/// <returns></returns>
public IEnumerable<IDictionary<string, object>> GetContentsByFolder(string folderName)
{
return GetContentsByFolder(folderName, string.Empty, string.Empty, null, 1, DefaultQuerySize, null);
}
/// <summary>
/// Gets the contents count.
/// </summary>
/// <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>
/// <returns></returns>
public int GetContentCountByFolder(string folderName, string queryStatement, NameValueCollection queryValues, TimeSpan? cacheTime)
{
var folder = GetFolder(folderName);
return ContentProvider.TextContentQuerier.SetQueryType(this.queryType).CountContents(DataContext, queryStatement
, queryValues.ToDictionary(), folder, folder.GetBaseFoldersRecusive(), cacheTime);
}
/// <summary>
/// Gets the content count by folder.
/// </summary>
/// <param name="folderName">Name of the folder.</param>
/// <returns></returns>
public int GetContentCountByFolder(string folderName)
{
return GetContentCountByFolder(folderName, string.Empty, null, null);
}
/// <summary>
/// Gets the contents by schema,disregard which folder this content belongs to.
/// </summary>
/// <param name="schemaName">Name of the 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>
/// <returns></returns>
public IEnumerable<IDictionary<string, object>> GetContentsBySchema(string schemaName, string queryStatement, string orderBy,
NameValueCollection queryValues, int startIndex, int pageSize, TimeSpan? cacheTime)
{
var schema = GetSchema(schemaName);
return ContentProvider.TextContentQuerier.SetQueryType(this.queryType).QuerySubContents(DataContext, queryStatement, orderBy, queryValues.ToDictionary(), schema,
null, startIndex, pageSize, cacheTime);
}
/// <summary>
/// Gets the contents from one schema disregarding which folder this content belongs to. Default return records count defined in DefaultQuerySize, default is 1000
/// </summary>
/// <param name="schemaName"></param>
/// <returns></returns>
public IEnumerable<IDictionary<string, object>> GetContentsBySchema(string schemaName)
{
return GetContentsBySchema(schemaName, string.Empty, string.Empty, null, 1, DefaultQuerySize, null);
}
/// <summary>
/// Gets the content count by schema.
/// </summary>
/// <param name="schemaName">Name of the 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 int GetContentCountBySchema(string schemaName, string queryStatement, NameValueCollection queryValues, TimeSpan? cacheTime)
{
var schema = GetSchema(schemaName);
return ContentProvider.TextContentQuerier.SetQueryType(this.queryType).CountSubContents(DataContext, queryStatement, queryValues.ToDictionary(), schema, null, cacheTime);
}
/// <summary>
/// Gets the content count by schema.
/// </summary>
/// <param name="schemaName">Name of the schema.</param>
/// <returns></returns>
public int GetContentCountBySchema(string schemaName)
{
return GetContentCountBySchema(schemaName, string.Empty, null, null);
}
#endregion
#region GetContentsByCategory
#region GetContentsByCategoryAndSchema
/// <summary>
/// Gets the contents by category and schema.
/// </summary>
/// <param name="categoryOriginalUUID">The category original UUID.</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 IEnumerable<IDictionary<string, object>> GetContentsByCategoryAndSchema(Guid categoryOriginalUUID, string schemaName,
string queryStatement, string orderBy, NameValueCollection queryValues, int startIndex, int pageSize, TimeSpan? cacheTime)
{
return GetContentsByCategoryAndSchema(new Guid[] { categoryOriginalUUID }, schemaName, queryStatement, orderBy, queryValues, startIndex, pageSize, cacheTime);
}
/// <summary>
/// Gets the contents by category and schema.
/// </summary>
/// <param name="categoryOriginalUUID">The category original UUID.</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 IEnumerable<IDictionary<string, object>> GetContentsByCategoryAndSchema(IEnumerable<Guid> categoryOriginalUUID, string schemaName,
string queryStatement, string orderBy, NameValueCollection queryValues, int startIndex, int pageSize, TimeSpan? cacheTime)
{
var schema = GetSchema(schemaName);
return ContentProvider.TextContentQuerier.SetQueryType(this.queryType).QueryContentsByCategory(DataContext, queryStatement, orderBy, queryValues.ToDictionary(), schema,
categoryOriginalUUID, startIndex, pageSize, cacheTime);
}
/// <summary>
/// Gets the content count by category and schema.
/// </summary>
/// <param name="categoryOriginalUUID">The category original UUID.</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 int GetContentCountByCategoryAndSchema(Guid categoryOriginalUUID, string schemaName, string queryStatement
, NameValueCollection queryValues, TimeSpan? cacheTime)
{
return GetContentCountByCategoryAndSchema(new Guid[] { categoryOriginalUUID }, schemaName, queryStatement, queryValues, cacheTime);
}
/// <summary>
/// Gets the content count by category and schema.
/// </summary>
/// <param name="categoryOriginalUUID">The category original UUID.</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 int GetContentCountByCategoryAndSchema(IEnumerable<Guid> categoryOriginalUUID, string schemaName, string queryStatement
, NameValueCollection queryValues, TimeSpan? cacheTime)
{
var schema = GetSchema(schemaName);
return ContentProvider.TextContentQuerier.SetQueryType(this.queryType).CountContentsByCategory(DataContext, queryStatement, queryValues.ToDictionary(), schema,
categoryOriginalUUID, cacheTime);
}
/// <summary>
/// Gets the contents by category and schema.
/// </summary>
/// <param name="categoryId">The category id.</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>
/// <returns></returns>
public IEnumerable<IDictionary<string, object>> GetContentsByCategoryAndSchema(int categoryId, string schemaName,
string queryStatement, string orderBy, NameValueCollection queryValues, int startIndex, int pageSize, TimeSpan? cacheTime)
{
return GetContentsByCategoryAndSchema(new int[] { categoryId }, schemaName, queryStatement, orderBy, queryValues, startIndex, pageSize, cacheTime);
}
/// <summary>
/// Gets the contents by category and schema.
/// </summary>
/// <param name="categoryId">The category id.</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>
/// <returns></returns>
public IEnumerable<IDictionary<string, object>> GetContentsByCategoryAndSchema(IEnumerable<int> categoryId, string schemaName,
string queryStatement, string orderBy, NameValueCollection queryValues, int startIndex, int pageSize, TimeSpan? cacheTime)
{
List<Guid> originalUUIDList = new List<Guid>();
foreach (var id in categoryId)
{
var categoryOriginalUUID = GetContentOriginalUUID(id);
if (categoryOriginalUUID.HasValue)
{
originalUUIDList.Add(categoryOriginalUUID.Value);
}
}
if (originalUUIDList.Count == 0)
{
return new List<IDictionary<string, object>>();
}
return GetContentsByCategoryAndSchema(originalUUIDList, schemaName, queryStatement, orderBy,
queryValues, startIndex, pageSize, cacheTime);
}
/// <summary>
/// Gets the content count by category with schema.
/// </summary>
/// <param name="categoryId">The category id.</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 int GetContentCountByCategoryAndSchema(int categoryId, string schemaName, string queryStatement, NameValueCollection queryValues, TimeSpan? cacheTime)
{
return GetContentCountByCategoryAndSchema(new int[] { categoryId }, schemaName, queryStatement, queryValues, cacheTime);
}
/// <summary>
/// Gets the content count by category with schema.
/// </summary>
/// <param name="categoryId">The category id.</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 int GetContentCountByCategoryAndSchema(IEnumerable<int> categoryId, string schemaName, string queryStatement, NameValueCollection queryValues, TimeSpan? cacheTime)
{
List<Guid> originalUUIDList = new List<Guid>();
foreach (var id in categoryId)
{
var categoryOriginalUUID = GetContentOriginalUUID(id);
if (categoryOriginalUUID.HasValue)
{
originalUUIDList.Add(categoryOriginalUUID.Value);
}
}
if (originalUUIDList.Count == 0)
{
return 0;
}
return GetContentCountByCategoryAndSchema(originalUUIDList, schemaName, queryStatement, queryValues, cacheTime);
}
#endregion
#region GetContentsByCategoryAndFolder
/// <summary>
/// Gets the contents by category and folder.
/// </summary>
/// <param name="categoryOriginalUUID">The content original UUID. This is the category original UUID, not the current category UUID because of the content inheritance. Current local application category UUID might not be able to retrieve data.</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 IEnumerable<IDictionary<string, object>> GetContentsByCategoryAndFolder(Guid categoryOriginalUUID, string folderName,
string queryStatement, string orderBy, NameValueCollection queryValues, int startIndex, int pageSize, TimeSpan? cacheTime)
{
return GetContentsByCategoryAndFolder(new Guid[] { categoryOriginalUUID }, folderName, queryStatement, orderBy, queryValues, startIndex, pageSize, cacheTime);
}
/// <summary>
/// Gets the contents by category and folder.
/// </summary>
/// <param name="categoryOriginalUUID">The content original UUID. This is the category original UUID, not the current category UUID because of the content inheritance. Current local application category UUID might not be able to retrieve data.</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 IEnumerable<IDictionary<string, object>> GetContentsByCategoryAndFolder(IEnumerable<Guid> categoryOriginalUUID, string folderName,
string queryStatement, string orderBy, NameValueCollection queryValues, int startIndex, int pageSize, TimeSpan? cacheTime)
{
var folder = GetFolder(folderName);
return ContentProvider.TextContentQuerier.SetQueryType(this.queryType).QueryContentsByCategory(DataContext, queryStatement, orderBy, queryValues.ToDictionary(),
folder, folder.GetBaseFoldersRecusive(), categoryOriginalUUID, startIndex, pageSize, cacheTime);
}
/// <summary>
/// Gets the contents by category and folder.
/// </summary>
/// <param name="categoryOriginalUUID">The content original UUID. This is the category original UUID, not the current category UUID because of the content inheritance. Current local application category UUID might not be able to retrieve data.</param>
/// <param name="folderName">name of the folder to retrieve content</param>
/// <returns></returns>
public IEnumerable<IDictionary<string, object>> GetContentsByCategoryAndFolder(Guid categoryOriginalUUID, string folderName)
{
return GetContentsByCategoryAndFolder(categoryOriginalUUID, folderName, string.Empty, string.Empty, null, 1, DefaultQuerySize, null);
}
/// <summary>
/// Gets the content count by category and folder.
/// </summary>
/// <param name="categoryOriginalUUID">The content original UUID. This is the category original UUID, not the current category UUID because of the content inheritance. Current local application category UUID might not be able to retrieve data.</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 int GetContentCountByCategoryAndFolder(Guid categoryOriginalUUID, string folderName, string queryStatement,
NameValueCollection queryValues, TimeSpan? cacheTime)
{
return GetContentCountByCategoryAndFolder(new Guid[] { categoryOriginalUUID }, folderName, queryStatement, queryValues, cacheTime);
}
/// <summary>
/// Gets the content count by category and folder.
/// </summary>
/// <param name="categoryOriginalUUID">The content original UUID. This is the category original UUID, not the current category UUID because of the content inheritance. Current local application category UUID might not be able to retrieve data.</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 int GetContentCountByCategoryAndFolder(IEnumerable<Guid> categoryOriginalUUID, string folderName, string queryStatement,
NameValueCollection queryValues, TimeSpan? cacheTime)
{
var folder = GetFolder(folderName);
return ContentProvider.TextContentQuerier.SetQueryType(this.queryType).CountContentsByCategory(DataContext, queryStatement, queryValues.ToDictionary(), folder
, folder.GetBaseFoldersRecusive(), categoryOriginalUUID, cacheTime);
}
/// <summary>
/// Gets the content count by category and folder.
/// </summary>
/// <param name="categoryOriginalUUID">The content original UUID. This is the category original UUID, not the current category UUID because of the content inheritance. Current local application category UUID might not be able to retrieve data.</param>
/// <param name="folderName">Name of the folder.</param>
/// <returns></returns>
public int GetContentCountByCategoryAndFolder(Guid categoryOriginalUUID, string folderName)
{
return GetContentCountByCategoryAndFolder(categoryOriginalUUID, folderName, string.Empty, null, null);
}
/// <summary>
/// Gets the content count by category and folder.
/// </summary>
/// <param name="categoryOriginalUUID">The content original UUID. This is the category original UUID, not the current category UUID because of the content inheritance. Current local application category UUID might not be able to retrieve data.</param>
/// <param name="folderName">Name of the folder.</param>
/// <returns></returns>
public int GetContentCountByCategoryAndFolder(IEnumerable<Guid> categoryOriginalUUID, string folderName)
{
return GetContentCountByCategoryAndFolder(categoryOriginalUUID, folderName, string.Empty, null, null);
}
/// <summary>
/// Gets the contents by categoryID and folder.
/// </summary>
/// <param name="categoryId">The ContentId of category schema</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 IEnumerable<IDictionary<string, object>> GetContentsByCategoryAndFolder(int categoryId, string folderName,
string queryStatement, string orderBy, NameValueCollection queryValues, int startIndex, int pageSize, TimeSpan? cacheTime)
{
return GetContentsByCategoryAndFolder(new int[] { categoryId }, folderName, queryStatement, orderBy, queryValues, startIndex, pageSize, cacheTime);
}
/// <summary>
/// Gets the contents by categoryID and folder.
/// </summary>
/// <param name="categoryId">The ContentId of category schema</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 IEnumerable<IDictionary<string, object>> GetContentsByCategoryAndFolder(IEnumerable<int> categoryId, string folderName,
string queryStatement, string orderBy, NameValueCollection queryValues, int startIndex, int pageSize, TimeSpan? cacheTime)
{
List<Guid> originalUUIDList = new List<Guid>();
foreach (var id in categoryId)
{
var categoryOriginalUUID = GetContentOriginalUUID(id);
if (categoryOriginalUUID.HasValue)
{
originalUUIDList.Add(categoryOriginalUUID.Value);
}
}
if (originalUUIDList.Count == 0)
{
return new List<IDictionary<string, object>>();
}
return GetContentsByCategoryAndFolder(originalUUIDList, folderName, queryStatement,
orderBy, queryValues, startIndex, pageSize, cacheTime);
}
/// <summary>
/// Gets the contents by category and folder.
/// </summary>
/// <param name="categoryId">The ContentId of category schema.</param>
/// <param name="folderName">Name of the folder.</param>
/// <returns></returns>
public IEnumerable<IDictionary<string, object>> GetContentsByCategoryAndFolder(int categoryId, string folderName)
{
return GetContentsByCategoryAndFolder(categoryId, folderName, string.Empty, string.Empty, null, 1, DefaultQuerySize, null);
}
/// <summary>
/// Gets the contents by category and folder.
/// </summary>
/// <param name="categoryId">The ContentId of category schema.</param>
/// <param name="folderName">Name of the folder.</param>
/// <returns></returns>
public IEnumerable<IDictionary<string, object>> GetContentsByCategoryAndFolder(IEnumerable<int> categoryId, string folderName)
{
return GetContentsByCategoryAndFolder(categoryId, folderName, string.Empty, string.Empty, null, 1, DefaultQuerySize, null);
}
/// <summary>
/// Gets the content count by category and folder.
/// </summary>
/// <param name="categoryId">The category id.</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 int GetContentCountByCategoryAndFolder(int categoryId, string folderName, string queryStatement
, NameValueCollection queryValues, TimeSpan? cacheTime)
{
return GetContentCountByCategoryAndFolder(new int[] { categoryId }, folderName, queryStatement, queryValues, cacheTime);
}
/// <summary>
/// Gets the content count by category and folder.
/// </summary>
/// <param name="categoryId">The category id.</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 int GetContentCountByCategoryAndFolder(IEnumerable<int> categoryId, string folderName, string queryStatement
, NameValueCollection queryValues, TimeSpan? cacheTime)
{
List<Guid> originalUUIDList = new List<Guid>();
foreach (var id in categoryId)
{
var categoryOriginalUUID = GetContentOriginalUUID(id);
if (categoryOriginalUUID.HasValue)
{
originalUUIDList.Add(categoryOriginalUUID.Value);
}
}
if (originalUUIDList.Count == 0)
{
return 0;
}
return GetContentCountByCategoryAndFolder(originalUUIDList, folderName, queryStatement, queryValues, cacheTime);
}
/// <summary>
/// Gets the content count by category and folder.
/// </summary>
/// <param name="categoryId">The category id.</param>
/// <param name="folderName">Name of the folder.</param>
/// <returns></returns>
public int GetContentCountByCategoryAndFolder(int categoryId, string folderName)
{
return GetContentCountByCategoryAndFolder(categoryId, folderName, string.Empty, null, null);
}
/// <summary>
/// Gets the content count by category and folder.
/// </summary>
/// <param name="categoryId">The category id.</param>
/// <param name="folderName">Name of the folder.</param>
/// <returns></returns>
public int GetContentCountByCategoryAndFolder(IEnumerable<int> categoryId, string folderName)
{
return GetContentCountByCategoryAndFolder(categoryId, folderName, string.Empty, null, null);
}
#endregion
#endregion
#region GetCategoriesByContent
#region GetCategoriesByContentAndSchema
/// <summary>
/// Gets the categories by content and schema.
/// </summary>
/// <param name="contentUUID">The content UUID. Not original UUID!</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 IEnumerable<IDictionary<string, object>> GetCategoriesByContentAndSchema(Guid contentUUID, string schemaName,
string queryStatement, string orderBy, NameValueCollection queryValues, int startIndex, int pageSize, TimeSpan? cacheTime)
{
var schema = GetSchema(schemaName);
return ContentProvider.TextContentQuerier.SetQueryType(this.queryType).QueryCategories(DataContext, queryStatement, orderBy, queryValues.ToDictionary(), schema,
contentUUID, startIndex, pageSize, cacheTime);
}
/// <summary>
/// Gets the categories by content and schema.
/// </summary>
/// <param name="contentUUID">The content UUID.</param>
/// <param name="schemaName">The cateogry schema of object returned.</param>
/// <returns></returns>
public IEnumerable<IDictionary<string, object>> GetCategoriesByContentAndSchema(Guid contentUUID, string schemaName)
{
return GetCategoriesByContentAndSchema(contentUUID, schemaName, string.Empty, string.Empty, null, 1, DefaultQuerySize, null);
}
/// <summary>
/// Gets the category count by content and category schema.
/// </summary>
/// <param name="contentUUID">The content UUID.Not original UUID!</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 int GetCategoryCountByContentAndSchema(Guid contentUUID, string schemaName, string queryStatement
, NameValueCollection queryValues, TimeSpan? cacheTime)
{
var schema = GetSchema(schemaName);
return ContentProvider.TextContentQuerier.SetQueryType(this.queryType).CountCategories(DataContext, queryStatement, queryValues.ToDictionary(), schema, contentUUID, cacheTime);
}
/// <summary>
/// Gets the category count by content and category schema.
/// </summary>
/// <param name="contentUUID">The content UUID.Not original UUID!</param>
/// <param name="schemaName">The cateogry schema of object returned.</param>
/// <returns></returns>
public int GetCategoryCountByContentAndSchema(Guid contentUUID, string schemaName)
{
return GetCategoryCountByContentAndSchema(contentUUID, schemaName, "", null, null);
}
/// <summary>
/// Gets the categories by content and schema.
/// </summary>
/// <param name="contentId">The contentId of content item.</param>
/// <param name="schemaName">Name of 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>
/// <returns></returns>
public IEnumerable<IDictionary<string, object>> GetCategoriesByContentAndSchema(int contentId, string schemaName,
string queryStatement, string orderBy, NameValueCollection queryValues, int startIndex, int pageSize, TimeSpan? cacheTime)
{
var contentUUID = GetContentUUID(contentId);
if (!contentUUID.HasValue)
{
return new List<IDictionary<string, object>>();
}
return GetCategoriesByContentAndSchema(contentUUID.Value, schemaName, queryStatement, orderBy, queryValues, startIndex, pageSize, cacheTime);
}
/// <summary>
/// Gets the categories by content and schema.
/// </summary>
/// <param name="contentId">The contentId of content item.</param>
/// <param name="schemaName">Name of the category schema.</param>
/// <returns></returns>
public IEnumerable<IDictionary<string, object>> GetCategoriesByContentAndSchema(int contentId, string schemaName)
{
return GetCategoriesByContentAndSchema(contentId, schemaName, string.Empty, string.Empty, null, 1, DefaultQuerySize, null);
}
/// <summary>
/// Gets the category count by content and schema.
/// </summary>
/// <param name="contentId">The contentId of content item.</param>
/// <param name="schemaName">Name of 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>
/// <returns></returns>
public int GetCategoryCountByContentAndSchema(int contentId, string schemaName, string queryStatement,
NameValueCollection queryValues, TimeSpan? cacheTime)
{
var contentUUID = GetContentUUID(contentId);
if (!contentUUID.HasValue)
{
return 0;
}
return GetCategoryCountByContentAndSchema(contentUUID.Value, schemaName, queryStatement, queryValues, cacheTime);
}
/// <summary>
/// Gets the category count by content and schema.
/// </summary>
/// <param name="contentId">The contentId of content item.</param>
/// <param name="schemaName">Name of the category schema.</param>
/// <returns></returns>
public int GetCategoryCountByContentAndSchema(int contentId, string schemaName)
{
return GetCategoryCountByContentAndSchema(contentId, schemaName, string.Empty, null, null);
}
#endregion
#region GetCategoriesByContentAndFolder
/// <summary>
/// Gets the categories by content and folder.
/// </summary>
/// <param name="contentUUID">The content UUID. Not original UUID!</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 IEnumerable<IDictionary<string, object>> GetCategoriesByContentAndFolder(Guid contentUUID, string folderName,
string queryStatement, string orderBy, NameValueCollection queryValues, int startIndex, int pageSize, TimeSpan? cacheTime)
{
var folder = GetFolder(folderName);
return ContentProvider.TextContentQuerier.SetQueryType(this.queryType).QueryCategories(DataContext, queryStatement, orderBy, queryValues.ToDictionary(),
folder, folder.GetBaseFoldersRecusive(), contentUUID, startIndex, pageSize, cacheTime);
}
/// <summary>
/// Gets the categories by content and folder.
/// </summary>
/// <param name="contentUUID">The UUID of the content.</param>
/// <param name="folderName">Name of the folder of category content.</param>
/// <returns></returns>
public IEnumerable<IDictionary<string, object>> GetCategoriesByContentAndFolder(Guid contentUUID, string folderName)
{
return GetCategoriesByContentAndFolder(contentUUID, folderName, string.Empty, string.Empty, null, 1, DefaultQuerySize, null);
}
/// <summary>
/// Gets the category content count by content and folder.
/// </summary>
/// <param name="contentUUID">The content UUID.</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>
/// <param name="cacheTime">The cache time.</param>
/// <returns></returns>
public int GetCategoryCountByContentAndFolder(Guid contentUUID, string folderName, string queryStatement,
NameValueCollection queryValues, TimeSpan? cacheTime)
{
var folder = GetFolder(folderName);
return ContentProvider.TextContentQuerier.SetQueryType(this.queryType).CountCategories(DataContext, queryStatement, queryValues.ToDictionary(), folder
, folder.GetBaseFoldersRecusive(), contentUUID, cacheTime);
}
/// <summary>
/// Gets the category content count by content and folder.
/// </summary>
/// <param name="contentUUID">The content UUID.</param>
/// <param name="folderName">Name of the folder of category content.</param>
/// <returns></returns>
public int GetCategoryCountByContentAndFolder(Guid contentUUID, string folderName)
{
return GetCategoryCountByContentAndFolder(contentUUID, folderName, string.Empty, null, null);
}
/// <summary>
/// Gets the categories by content and folder.
/// </summary>
/// <param name="contentId">The content id.</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 IEnumerable<IDictionary<string, object>> GetCategoriesByContentAndFolder(int contentId, string folderName,
string queryStatement, string orderBy, NameValueCollection queryValues, int startIndex, int pageSize, TimeSpan? cacheTime)
{
var contentUUID = GetContentUUID(contentId);
if (!contentUUID.HasValue)
{
return new List<IDictionary<string, object>>();
}
return GetCategoriesByContentAndFolder(contentUUID.Value, folderName, queryStatement,
orderBy, queryValues, startIndex, pageSize, cacheTime);
}
/// <summary>
/// Gets the categories by content and folder.
/// </summary>
/// <param name="contentId">The content id.</param>
/// <param name="folderName">Name of the folder of category content.</param>
/// <returns></returns>
public IEnumerable<IDictionary<string, object>> GetCategoriesByContentAndFolder(int contentId, string folderName)
{
return GetCategoriesByContentAndFolder(contentId, folderName, string.Empty, string.Empty, null, 1, DefaultQuerySize, null);
}
/// <summary>
/// Gets the category content count by category and folder.
/// </summary>
/// <param name="contentId">The content id.</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>
/// <param name="cacheTime">The cache time.</param>
/// <returns></returns>
public int GetCategoryCountByContentAndFolder(int contentId, string folderName, string queryStatement
, NameValueCollection queryValues, TimeSpan? cacheTime)
{
var contentUUID = GetContentUUID(contentId);
if (!contentUUID.HasValue)
{
return 0;
}
return GetCategoryCountByContentAndFolder(contentUUID.Value, folderName, queryStatement, queryValues, cacheTime);
}
/// <summary>
/// Gets the category content count by content and folder.
/// </summary>
/// <param name="contentId">The content id.</param>
/// <param name="folderName">Name of the folder of category content.</param>
/// <returns></returns>
public int GetCategoryCountByContentAndFolder(int contentId, string folderName)
{
return GetCategoryCountByContentAndFolder(contentId, folderName, string.Empty, null, null);
}
#endregion
#endregion
#region GetSubContents
/// <summary>
/// Gets the sub contents of current content item
/// </summary>
/// <param name="parentContentId">The current/parent content id.</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 IEnumerable<IDictionary<string, object>> GetSubContents(int parentContentId, string schemaName
, string queryStatement, string orderBy, NameValueCollection queryValues, int startIndex, int pageSize, TimeSpan? cacheTime)
{
var parentContentUUID = GetContentUUID(parentContentId);
var schema = CachedData.GetSchema(Application.ApplicationName, schemaName);
return ContentProvider.TextContentQuerier.SetQueryType(this.queryType).QuerySubContents(DataContext, queryStatement, orderBy, queryValues.ToDictionary(), schema,
parentContentUUID.Value, startIndex, pageSize, cacheTime);
}
/// <summary>
/// Gets the sub contents of current content item
/// </summary>
/// <param name="parentContentId">the current/parent content id </param>
/// <param name="schemaName">Name of the schema of subcontent</param>
/// <returns></returns>
public IEnumerable<IDictionary<string, object>> GetSubContents(int parentContentId, string schemaName)
{
return GetSubContents(parentContentId, schemaName, "", "", null, 0, DefaultQuerySize, null);
}
/// <summary>
/// Gets the sub contents.
/// </summary>
/// <param name="parentContentUUID">The parent content UUID.</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 IEnumerable<IDictionary<string, object>> GetSubContents(Guid parentContentUUID, string schemaName
, string queryStatement, string orderBy, NameValueCollection queryValues, int startIndex, int pageSize, TimeSpan? cacheTime)
{
var schema = CachedData.GetSchema(Application.ApplicationName, schemaName);
return ContentProvider.TextContentQuerier.SetQueryType(this.queryType).QuerySubContents(DataContext, queryStatement, orderBy, queryValues.ToDictionary(), schema,
parentContentUUID, startIndex, pageSize, cacheTime);
}
/// <summary>
/// Gets the sub contents.
/// </summary>
/// <param name="parentContentUUID">The parent content UUID.</param>
/// <param name="schemaName">Name of the schema of subcontent.</param>
/// <returns></returns>
public IEnumerable<IDictionary<string, object>> GetSubContents(Guid parentContentUUID, string schemaName)
{
return GetSubContents(parentContentUUID, schemaName, string.Empty, string.Empty, null, 1, DefaultQuerySize, null);
}
/// <summary>
/// Gets the sub content count of current content item
/// </summary>
/// <param name="parentContentId">The current/parent content id.</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 int GetSubContentCount(int parentContentId, string schemaName, string queryStatement, NameValueCollection queryValues, TimeSpan? cacheTime)
{
var parentContentUUID = GetContentUUID(parentContentId);
var schema = CachedData.GetSchema(Application.ApplicationName, schemaName);
return ContentProvider.TextContentQuerier.SetQueryType(this.queryType).CountSubContents(DataContext, queryStatement,
queryValues.ToDictionary(), schema, parentContentUUID.Value, cacheTime);
}
/// <summary>
/// Gets the sub content count of current content item
/// </summary>
/// <param name="parentContentId">The current/parent content id.</param>
/// <param name="schemaName">Name of the schema of subcontent.</param>
/// <returns></returns>
public int GetSubContentCount(int parentContentId, string schemaName)
{
return GetSubContentCount(parentContentId, schemaName, string.Empty, null, null);
}
/// <summary>
/// Gets the sub content count.
/// </summary>
/// <param name="parentContentUUID">The parent content UUID.</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 int GetSubContentCount(Guid parentContentUUID, string schemaName, string queryStatement, NameValueCollection queryValues, TimeSpan? cacheTime)
{
var schema = CachedData.GetSchema(Application.ApplicationName, schemaName);
return ContentProvider.TextContentQuerier.SetQueryType(this.queryType).CountSubContents(DataContext, queryStatement,
queryValues.ToDictionary(), schema, parentContentUUID, cacheTime);
}
/// <summary>
/// Gets the sub content count.
/// </summary>
/// <param name="parentContentUUID">The parent content UUID.</param>
/// <param name="schemaName">Name of the schema.</param>
/// <returns></returns>
public int GetSubContentCount(Guid parentContentUUID, string schemaName)
{
return GetSubContentCount(parentContentUUID, schemaName, string.Empty, null, null);
}
#endregion
#region BinaryContent
/// <summary>
/// Gets the binary content by id.
/// </summary>
/// <param name="contentId">The binary content id.</param>
/// <param name="cacheTime">The cache time.</param>
/// <returns></returns>
public IDictionary<string, object> GetBinaryContentById(int contentId, TimeSpan? cacheTime)
{
string queryStatement = "ContentId={ContentId}";
NameValueCollection na = new NameValueCollection();
na.Add("ContentId", contentId.ToString());
return ContentProvider.BinaryContentQuerier.SetQueryType(this.queryType).QueryContent(DataContext, queryStatement, "", na.ToDictionary(), cacheTime);
}
/// <summary>
/// Gets the binary content by UUID.
/// </summary>
/// <param name="contentUUID">The binary content UUID.</param>
/// <param name="cacheTime">The cache time.</param>
/// <returns></returns>
public IDictionary<string, object> GetBinaryContentByUUID(Guid contentUUID, TimeSpan? cacheTime)
{
string queryStatement = "ContentUUID={ContentUUID}";
NameValueCollection na = new NameValueCollection();
na.Add("ContentUUID", contentUUID.ToString());
return ContentProvider.BinaryContentQuerier.SetQueryType(this.queryType).QueryContent(DataContext, queryStatement, "", na.ToDictionary(), cacheTime);
}
/// <summary>
/// Gets the binary content by user key.
/// </summary>
/// <param name="userKey">The user key.</param>
/// <param name="cacheTime">The cache time.</param>
/// <returns></returns>
public IDictionary<string, object> GetBinaryContentByUserKey(string userKey, TimeSpan? cacheTime)
{
string queryStatement = "UserKey={UserKey}";
NameValueCollection na = new NameValueCollection();
na.Add("UserKey", userKey);
return ContentProvider.BinaryContentQuerier.SetQueryType(this.queryType).QueryContent(DataContext, queryStatement, "", na.ToDictionary(), cacheTime);
}
/// <summary>
/// Gets the binary contents.
/// </summary>
/// <param name="folderName">Name of the binary content 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 IEnumerable<IDictionary<string, object>> GetBinaryContents(string folderName, string queryStatement, string orderBy,
NameValueCollection queryValues, int startIndex, int pageSize, TimeSpan? cacheTime)
{
var folder = GetFolder(folderName);
return ContentProvider.BinaryContentQuerier.SetQueryType(this.queryType).QueryContents(DataContext, queryStatement, orderBy, queryValues.ToDictionary(), folder
, folder.GetBaseFoldersRecusive(), startIndex, pageSize, cacheTime);
}
/// <summary>
/// Gets the binary contents.
/// </summary>
/// <param name="folderName">Name of the binary content folder.</param>
/// <returns></returns>
public IEnumerable<IDictionary<string, object>> GetBinaryContents(string folderName)
{
return GetBinaryContents(folderName, string.Empty, string.Empty, null, 1, DefaultQuerySize, null);
}
/// <summary>
/// Gets the binary content count.
/// </summary>
/// <param name="folderName">Name of binary content 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 int GetBinaryContentCount(string folderName, string queryStatement, NameValueCollection queryValues, TimeSpan? cacheTime)
{
var folder = GetFolder(folderName);
return ContentProvider.BinaryContentQuerier.SetQueryType(this.queryType).CountContents(DataContext, queryStatement
, queryValues.ToDictionary(), folder, folder.GetBaseFoldersRecusive(), cacheTime);
}
/// <summary>
/// Gets the binary content count.
/// </summary>
/// <param name="folderName">Name of binary content folder.</param>
/// <returns></returns>
public int GetBinaryContentCount(string folderName)
{
return GetBinaryContentCount(folderName, string.Empty, null, null);
}
#endregion
#region Relation Manage
/// <summary>
/// Adds the binary content to text content.
/// </summary>
/// <param name="textContentUUID">The text content UUID.</param>
/// <param name="binaryContentUUID">The binary content UUID.</param>
public void AddBinaryContentToContent(Guid textContentUUID, Guid binaryContentUUID)
{
TextContentService textContentService = UnityManager.Resolve<TextContentService>();
textContentService.AddBinaryContentToContent(textContentUUID, binaryContentUUID);
}
/// <summary>
/// Removes the binary content from text content.
/// </summary>
/// <param name="textContentUUID">The text content UUID.</param>
/// <param name="binaryContentUUID">The binary content UUID.</param>
public void RemoveBinaryContentFromContent(Guid textContentUUID, Guid binaryContentUUID)
{
TextContentService textContentService = UnityManager.Resolve<TextContentService>();
textContentService.RemoveBinaryContentFromContent(textContentUUID, binaryContentUUID);
}
/// <summary>
/// Adds the category to content.
/// </summary>
/// <param name="contentUUID">The content UUID.</param>
/// <param name="categoryUUID">The category UUID.</param>
public void AddCategoryToContent(Guid contentUUID, Guid categoryUUID)
{
TextContentService textContentService = UnityManager.Resolve<TextContentService>();
textContentService.AddCategoryToContent(contentUUID, categoryUUID);
}
/// <summary>
/// Removes the category from text content.
/// </summary>
/// <param name="contentUUID">The content UUID.</param>
/// <param name="categoryUUID">The category UUID.</param>
public void RemoveCategoryFromContent(Guid contentUUID, Guid categoryUUID)
{
TextContentService textContentService = UnityManager.Resolve<TextContentService>();
textContentService.RemoveCategoryFromContent(contentUUID, categoryUUID);
}
#endregion
}
}
|