Ejemplo n.º 1
0
        public static bool Update(SysUser model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            ISysUser factory = SysUserFactory.GetFactory();
            bool     result  = factory.Update(model);

            if (result)
            {
                OperateLogServices.AddOperateLog <SysUser>(model, OperateType.Update);
            }
            return(result);
        }
Ejemplo n.º 2
0
        public static bool Update(SysUser model, List <SysUserRolesMapping> useRoleMappings, List <SysUserScopeMapping> useScopeMappings)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }
            if (useRoleMappings == null || useRoleMappings.Count == 0)
            {
                throw new ArgumentNullException("useRoleMappings");
            }
            if (useScopeMappings == null || useScopeMappings.Count == 0)
            {
                throw new ArgumentNullException("useScopeMappings");
            }

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

            using (DbOperator dbOperator = ConnectionManager.CreateConnection())
            {
                try
                {
                    dbOperator.BeginTransaction();
                    bool result = factory.Update(model, dbOperator);
                    if (!result)
                    {
                        throw new MyException("修改用户信息失败");
                    }

                    roleFactory.DeleteByUserId(model.RecordID, dbOperator);
                    result = roleFactory.Add(useRoleMappings, dbOperator);
                    if (!result)
                    {
                        throw new MyException("修改模块授权信息失败");
                    }

                    scopeFactory.DeleteByUserID(model.RecordID, dbOperator);
                    result = scopeFactory.Add(useScopeMappings, dbOperator);
                    if (!result)
                    {
                        throw new MyException("修改作用域授权信息失败");
                    }

                    dbOperator.CommitTransaction();
                    if (result)
                    {
                        OperateLogServices.AddOperateLog <SysUser>(model, OperateType.Update);
                        OperateLogServices.AddOperateLog(OperateType.Delete, string.Format("UserRolesMapping,UserId:{0}", model.RecordID));
                        OperateLogServices.AddOperateLog(OperateType.Delete, string.Format("UserScopeMapping,UserId:{0}", model.RecordID));

                        foreach (var item in useRoleMappings)
                        {
                            OperateLogServices.AddOperateLog <SysUserRolesMapping>(item, OperateType.Add);
                        }
                        foreach (var item in useScopeMappings)
                        {
                            OperateLogServices.AddOperateLog <SysUserScopeMapping>(item, OperateType.Add);
                        }
                    }
                    return(result);
                }
                catch {
                    dbOperator.RollbackTransaction();
                    throw;
                }
            }
        }