实现接口及服务
在Libraries\Nop.Services\Catalog中添加并实现接口ICategoryAttributeService与服务CategoryAttributeService,以便在控制器中使用接口ICategoryAttributeService。
添加接口与服务后,项目文件结构图如下:
接口代码为:
usingNop.Core;
namespaceNop.Services.Catalog
{
/*********************************************************
* 作 者:zaxx
* 创建时间:2015年12月11日 14:40:26
* 功能描述:
*
* 更改历史:
*
********************************************************/
///<summary>
/// 接口ICategoryAttributeService:
///<para> zaxx 2015年12月11日14:40:26</para>
///</summary>
public interfaceICategoryAttributeService
{
///<summary>
/// Gets allcategory attributes.
///<para>zaxx 2015-12-11 15:29:27</para>
///</summary>
///<paramname="pageIndex">Index ofthe page.</param>
///<paramname="pageSize">Size ofthe page.</param>
///<returns>IPagedList<CategoryAttribute>.</returns>
IPagedList<CategoryAttribute>GetAllCategoryAttributes(int pageIndex = 0,int pageSize= int.MaxValue);
}
}
服务代码为:
using System;
usingSystem.Linq;
usingNop.Core;
usingNop.Core.Caching;
usingNop.Core.Data;
namespaceNop.Services.Catalog
{
/*********************************************************
* 作 者:zaxx
* 创建时间:2015年12月11日 14:40:46
* 功能描述:
*
* 更改历史:
*
********************************************************/
///<summary>
/// 类CategoryAttributeService:
///<para> zaxx 2015年12月11日14:40:46</para>
///</summary>
public classCategoryAttributeService : ICategoryAttributeService
{
#region Fields
private readonlyIRepository<CategoryAttribute> _categoryAttributeRepository;
private readonlyICacheManager_cacheManager;
#endregion
#region Ctor
publicCategoryAttributeService(IRepository<CategoryAttribute>categoryAttributeRepository,ICacheManager cacheManager)
{
_categoryAttributeRepository =categoryAttributeRepository;
_cacheManager = cacheManager;
}
#endregion
#regionConstants
///<summary>
/// Key for caching
///</summary>
///<remarks>
/// {0} : page index
/// {1} : page size
///</remarks>
private conststringCategoryAttributesAllKey = "Nop.CategoryAttribute.all-{0}-{1}";
#endregion
#region Methods
public IPagedList<CategoryAttribute>GetAllCategoryAttributes(int pageIndex = 0,int pageSize= Int32.MaxValue)
{
string key = string.Format(CategoryAttributesAllKey,pageIndex, pageSize);
return_cacheManager.Get(key, () =>
{
var query = from pa in (IQueryable<RsWebServiceBll.NopWDSReference.CategoryAttribute>)_categoryAttributeRepository.Table
orderby pa.Name
select pa;
varproductAttributes = new PagedList<CategoryAttribute>(query,pageIndex, pageSize);
returnproductAttributes;
});
}
#endregion
}
}
个人推广:文章代写与软件开发