コード例 #1
0
ファイル: UserController.cs プロジェクト: sulin888/LsProject
        public JsonResult DelUser(int id)
        {
            var r = SysPower(SysMenuConstant.MENU_USER_MANAGE, SysMenuConstant.FUN_DELETE, UserInfo.UserCode, false);

            if (!r)
            {
                return(new CustomerJsonResult(new ResponseResult {
                    code = ResponseHelper.FAILCODE, msg = "无删除权限"
                }));
            }
            int result = ISysUserService.Delete(id.ToString());

            if (result > 0)
            {
                return(new CustomerJsonResult(new ResponseResult {
                    code = ResponseHelper.ESUCCESSCODE, msg = "删除成功"
                }));
            }
            else
            {
                return(new CustomerJsonResult(new ResponseResult {
                    code = ResponseHelper.FAILCODE, msg = "删除失败"
                }));
            }
        }
コード例 #2
0
        public static bool Delete(string recordId)
        {
            if (string.IsNullOrWhiteSpace(recordId))
            {
                throw new ArgumentNullException("recordId");
            }

            ISysUser factory = SysUserFactory.GetFactory();

            SysUser model = factory.QuerySysUserByRecordId(recordId);

            if (model == null)
            {
                throw new MyException("待删除的用户不存在");
            }

            if (model.IsDefaultUser == YesOrNo.Yes)
            {
                throw new MyException("该用户为系统默认用户不能删除");
            }

            ISysUserRolesMapping roleFactory  = SysUserRolesMappingFactory.GetFactory();
            ISysUserScopeMapping scopeFactory = SysUserScopeMappingFactory.GetFactory();

            using (DbOperator dbOperator = ConnectionManager.CreateConnection())
            {
                try
                {
                    dbOperator.BeginTransaction();
                    bool result = factory.Delete(recordId, dbOperator);
                    if (!result)
                    {
                        throw new MyException("添加用户信息失败");
                    }

                    roleFactory.DeleteByUserId(recordId, dbOperator);
                    scopeFactory.DeleteByUserID(recordId, dbOperator);

                    dbOperator.CommitTransaction();
                    if (result)
                    {
                        OperateLogServices.AddOperateLog(OperateType.Delete, string.Format("RecordId:{0}", recordId));
                    }
                    return(true);
                }
                catch
                {
                    dbOperator.RollbackTransaction();
                    throw;
                }
            }
        }