Beispiel #1
0
        public async Task <BaseApiResponse> SetNickName(SetNickNameRequest request)
        {
            request.CheckNotNull(nameof(request));
            TryInitUserModel();

            if (request.NickName.Length > 20)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "昵称长度不得超过20字符."
                });
            }
            //更新
            var command = new UpdateNickNameCommand(request.NickName)
            {
                AggregateRootId = _user.Id
            };
            var result = await ExecuteCommandAsync(command);

            if (!result.IsSuccess())
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage())
                });
            }

            //更新缓存
            _user.NickName = request.NickName;
            _apiSession.UpdateUserInfo(_user.Id.ToString(), _user);

            return(new BaseApiResponse());
        }
Beispiel #2
0
        public async Task <BaseApiResponse> SetNickName([FromBody] SetNickNameRequest request)
        {
            request.CheckNotNull(nameof(request));
            var currentAccount = _contextService.GetCurrentAccount(HttpContext);

            if (request.NickName.Length > 20)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "昵称长度不得超过20字符."
                });
            }
            //更新
            var command = new UpdateNickNameCommand(request.NickName)
            {
                AggregateRootId = currentAccount.UserId.ToGuid()
            };
            var result = await ExecuteCommandAsync(command);

            if (!result.IsSuccess())
            {
                return(new BaseApiResponse {
                    Code = 400, Message = "命令没有执行成功:{0}".FormatWith(result.GetErrorMessage())
                });
            }

            return(new BaseApiResponse());
        }