为NopCommerce添加新的业务逻辑

来源:互联网 发布:爬虫软件是什么 编辑:程序博客网 时间:2024/04/28 01:50

在NopCommerce框架下,添加新的业务逻辑,步骤如下:

步骤一:

在目录Libraries/Nop.BusinessLogic下创建实体类Standard.cs(公司项目)与业务逻辑类StandardManager.cs

步骤二:

在Libraries/Nop.BusinessLogic/Data/NopObjectContext.cs文件中添加属性

        public ObjectSet<Standard> Standards        {            get            {                if (_standards == null)                {                    _standards = CreateObjectSet<Standard>();                }                return _standards;            }        }        private ObjectSet<Standard> _standards;

步骤三:

在Libraries/Nop.BusinessLogic/Data/NopObjectContext.cs文件中添加相应的数据库操作(存储过程转化为函数)

        public List<Standard> Sq_StandardLoadAllPaged(int pageIndex, int pageSize, out int totalRecords)        {            totalRecords = 0;            ObjectParameter PageIndexParameter = new ObjectParameter("PageIndex", pageIndex);            ObjectParameter PageSizeParameter = new ObjectParameter("PageSize", pageSize);            ObjectParameter LanguageParameter = new ObjectParameter("LanguageID", NopContext.Current.WorkingLanguage.LanguageId);            ObjectParameter totalRecordsParameter = new ObjectParameter("TotalRecords", typeof(int));            var result = base.ExecuteFunction<Standard>("Sq_StandardLoadAllPaged", PageIndexParameter,                 PageSizeParameter, LanguageParameter, totalRecordsParameter).ToList();            totalRecords = Convert.ToInt32(totalRecordsParameter.Value);            return result;        }

基中Sq_StandardLoadAllPaged是从存储过程转化为函数

步骤四:

在目录Libraries/Nop.BusinessLogic业务逻辑类StandardManager.cs文件中添加相应的业务逻辑处理

        public static List<Standard> StandardLoadAllPaged(int pageIndex, int pageSize, out int totalRecords)        {            var context = ObjectContextHelper.CurrentObjectContext;            List<Standard> allStandard = context.Sq_StandardLoadAllPaged(pageIndex, pageSize, out totalRecords);            return allStandard;        }


 

 



 

原创粉丝点击