Ejemplo n.º 1
0
        /// <summary>
        /// 删除系统模块
        /// </summary>
        /// <param name="item">模块实例</param>
        /// <returns></returns>
        protected override int DoDelete(Module item)
        {
            Module module = DoGet(item.Id);

            if (module == null)
            {
                throw new BusinessLogicException("数据不存在");
            }
            ICollection <Module> children = DoGetChildren(item.Id);

            if (children.Count > 0)
            {
                throw new BusinessLogicException("请先删除子节点");
            }
            int affectRows;
            RoleModuleManager    roleModuleManager    = serviceProvider.GetRequiredService <RoleModuleManager>();
            VersionModuleManager versionModuleManager = serviceProvider.GetRequiredService <VersionModuleManager>();

            MultiMerchant.Merchant.BusinessLogic.RoleModuleManager merchantRoleModuleManager = serviceProvider.GetRequiredService <MultiMerchant.Merchant.BusinessLogic.RoleModuleManager>();

            //如果不是根节点判断是否还有兄弟节点
            if (!string.IsNullOrEmpty(module.ParentId))
            {
                ICollection <Module> brothers = DoGetChildren(module.ParentId).Where(p => p.Id != item.Id).ToList();
                if (brothers.Count == 0)
                {
                    Module parent = DoGet(module.ParentId);
                    affectRows = ProcessWithTransaction((transaction) =>
                    {
                        int rows = dal.UpdateNode(parent.Id, 0, transaction);
                        rows    += dal.Delete(item, transaction);
                        rows    += roleModuleManager.Dal.DeleteByModuleId(item.Id, transaction);
                        rows    += merchantRoleModuleManager.Dal.DeleteByModuleId(item.Id, transaction);
                        rows    += versionModuleManager.Dal.DeleteByModuleId(item.Id, transaction);
                        if (rows > 0)
                        {
                            operateHistoryManager.Insert(item.Id, item, DataOperationType.Delete, transaction: transaction);
                        }
                        return(rows);
                    });
                    if (affectRows > 0)
                    {
                        RemoveCache();
                    }
                    return(affectRows);
                }
            }
            affectRows = ProcessWithTransaction((transaction) =>
            {
                int rows = dal.Delete(item, transaction);
                rows    += roleModuleManager.Dal.DeleteByModuleId(item.Id, transaction);
                rows    += merchantRoleModuleManager.Dal.DeleteByModuleId(item.Id, transaction);
                if (rows > 0)
                {
                    operateHistoryManager.Insert(item.Id, item, DataOperationType.Delete, transaction: transaction);
                }
                return(rows);
            });
            return(affectRows);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="configuration">配置实例</param>
 /// <param name="serviceProvider">数据提供程序</param>
 public VersionManager(IConfiguration configuration, IServiceProvider serviceProvider) : base(configuration)
 {
     this.serviceProvider  = serviceProvider;
     versionModuleManager  = serviceProvider.GetRequiredService <VersionModuleManager>();
     operateHistoryManager = serviceProvider.GetRequiredService <IOperateHistoryManager>();
 }