Exemplo n.º 1
0
        public async Task <JsonResult> EditLoginUserPassWord([FromBody] FMEditLoginUserPassWord entity)
        {
            var jm = new AdminUiCallBack();

            if (string.IsNullOrEmpty(entity.oldPassword))
            {
                jm.msg = "请键入旧密码";
                return(new JsonResult(jm));
            }

            if (string.IsNullOrEmpty(entity.password))
            {
                jm.msg = "请键入新密码";
                return(new JsonResult(jm));
            }

            if (string.IsNullOrEmpty(entity.repassword))
            {
                jm.msg = "请键入新密码确认密码";
                return(new JsonResult(jm));
            }

            if (entity.password != entity.repassword)
            {
                jm.msg = "新密码与确认密码不相符";
                return(new JsonResult(jm));
            }

            if (CommonHelper.Md5For32(entity.oldPassword) == CommonHelper.Md5For32(entity.password))
            {
                jm.msg = "新密码与旧密码相同,无需修改";
                return(new JsonResult(jm));
            }

            var userModel = await _sysUserServices.QueryByIdAsync(_user.ID);

            if (userModel.passWord != CommonHelper.Md5For32(entity.oldPassword))
            {
                jm.msg = "旧密码输入错误";
                return(new JsonResult(jm));
            }

            userModel.passWord = CommonHelper.Md5For32(entity.password);
            var bl = await _sysUserServices.UpdateAsync(userModel);

            jm.code = bl ? 0 : 1;
            jm.msg  = bl ? "修改成功" : "修改失败";
            return(new JsonResult(jm));
        }
Exemplo n.º 2
0
        public async Task <JsonResult> DoEdit([FromBody] SysUser entity)
        {
            var jm = new AdminUiCallBack();

            var oldModel = await _sysUserServices.QueryByIdAsync(entity.id);

            if (oldModel == null)
            {
                jm.msg = "不存在此信息";
                return(new JsonResult(jm));
            }


            if (oldModel.userName != entity.userName)
            {
                var haveName = await _sysUserServices.ExistsAsync(p => p.userName == entity.userName);

                if (haveName)
                {
                    jm.msg = "账号已经存在";
                    return(new JsonResult(jm));
                }
            }

            //事物处理过程开始
            oldModel.userName = entity.userName;
            if (!string.IsNullOrEmpty(entity.passWord))
            {
                var md5Str = CommonHelper.Md5For32(entity.passWord);
                oldModel.passWord = md5Str;
            }

            oldModel.organizationId = entity.organizationId > 0 ? entity.organizationId : 0;
            oldModel.nickName       = entity.nickName;
            oldModel.sex            = entity.sex;
            oldModel.phone          = entity.phone;
            oldModel.updateTime     = DateTime.Now;

            //事物处理过程结束
            var bl = await _sysUserServices.UpdateAsync(oldModel);

            if (bl)
            {
                await _sysUserRoleServices.DeleteAsync(p => p.userId == oldModel.id);

                if (!string.IsNullOrEmpty(entity.roleIds))
                {
                    var strIds = entity.roleIds.Split(",");
                    var ids    = CommonHelper.StringArrAyToIntArray(strIds);
                    if (ids.Any())
                    {
                        var userRoles = new List <SysUserRole>();
                        foreach (var itemRoleId in ids)
                        {
                            userRoles.Add(new SysUserRole
                            {
                                createTime = DateTime.Now,
                                roleId     = itemRoleId,
                                userId     = oldModel.id
                            });
                        }
                        if (userRoles.Any())
                        {
                            await _sysUserRoleServices.InsertAsync(userRoles);
                        }
                    }
                }
            }

            jm.code = bl ? 0 : 1;
            jm.msg  = bl ? GlobalConstVars.EditSuccess : GlobalConstVars.EditFailure;

            return(new JsonResult(jm));
        }