为NopCommerce添加新的业务逻辑

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

步骤一:

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

步骤二:

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

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

步骤三:

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

        public List 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("Sq_StandardLoadAllPaged", PageIndexParameter, 
                PageSizeParameter, LanguageParameter, totalRecordsParameter).ToList();
            totalRecords = Convert.ToInt32(totalRecordsParameter.Value);
            return result;
        }

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

步骤四:

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

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


 

 



 

你可能感兴趣的:(NopCommerce)