NopCommerce添加新功能“类型属性”【添加服务接口及服务实现】

实现接口及服务

  在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&lt;CategoryAttribute&gt;.</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

    }

}

个人推广:文章代写与软件开发

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值