Exemplo n.º 1
0
        public async Task <Result> ModifyNameOrAvatar([FromBody] AccountModifyNameOrAvatarRequestDto dto)
        {
            //验证请求数据合法性
            var result = dto.Valid();

            if (!result.Success)
            {
                return(result);
            }

            //修改昵称和头像
            int id           = HttpContext.User.UserId();
            var modifyResult = await this._serviceProvider.GetRequiredService <AccountInfoChangeService>()
                               .ModifyNameOrAvatar(id, dto.Name, dto.Avatar);

            if (!modifyResult.Success)
            {
                return(modifyResult);
            }

            //数据持久化
            _operateLog.Record(ASFPermissions.AccountModifyInfo, new { uid = id, data = dto }, "Success");  //记录日志
            await _accountRepository.ModifyAsync(modifyResult.Data);

            await _unitOfWork.CommitAsync(autoRollback : true);

            return(Result.ReSuccess());
        }
        public async Task <Result> ModifyNameOrAvatar(AccountModifyNameOrAvatarRequestDto dto)
        {
            //验证请求数据合法性
            var result = dto.Valid();

            if (!result.Success)
            {
                return(result);
            }

            //修改昵称和头像
            int id           = 0;
            var modifyResult = await IocManager.Instance.Resolve <AccountInfoChangeService>()
                               .ModifyNameOrAvatar(id, dto.Name, dto.Avatar);

            if (!modifyResult.Success)
            {
                return(modifyResult);
            }

            //数据持久化
            _operateLog.Record(ASFPermissions.AccountModifyInfo, new { uid = id, data = dto }, "Success");  //记录日志
            await _accountRepository.ModifyAsync(modifyResult.Data);

            return(Result.ReSuccess());
        }