コード例 #1
0
        public ResultDto Post([FromBody] CreateMessageBoardDto createMessageBoardDto)
        {
            MessageBoard messageBoard = _mapper.Map <MessageBoard>(createMessageBoardDto);

            messageBoard.Ip       = this.GetIp();
            messageBoard.Agent    = Request.Headers["User-agent"].ToString();
            messageBoard.UserHost = Dns.GetHostName();
            messageBoard.System   = LinCmsUtils.GetOsNameByUserAgent(messageBoard.Agent);
            if (messageBoard.Ip.IsNotNullOrEmpty())
            {
                IpQueryResult ipQueryResult = LinCmsUtils.IpQueryCity(messageBoard.Ip);
                messageBoard.GeoPosition = ipQueryResult.errno == 0 ? ipQueryResult.data : ipQueryResult.errmsg;
            }

            LinUser linUser = _userService.GetCurrentUser();

            if (linUser == null)
            {
                messageBoard.Avatar = "/assets/user/" + new Random().Next(1, 360) + ".png";
            }
            else
            {
                messageBoard.Avatar = _currentUser.GetFileUrl(linUser.Avatar);
            }

            _messageBoardRepository.Insert(messageBoard);
            return(ResultDto.Success("留言成功"));
        }
コード例 #2
0
        public async Task CreateAsync(CreateMessageBoardDto createMessageBoardDto)
        {
            MessageBoard messageBoard = _mapper.Map <MessageBoard>(createMessageBoardDto);

            messageBoard.Ip       = this.GetIp();
            messageBoard.Agent    = _httpContextAccessor.HttpContext.Request.Headers["User-agent"].ToString();
            messageBoard.UserHost = Dns.GetHostName();
            messageBoard.System   = LinCmsUtils.GetOsNameByUserAgent(messageBoard.Agent);
            if (messageBoard.Ip.IsNotNullOrEmpty())
            {
                IpQueryResult ipQueryResult = LinCmsUtils.IpQueryCity(messageBoard.Ip);
                messageBoard.GeoPosition = ipQueryResult.errno == 0 ? ipQueryResult.data : ipQueryResult.errmsg;
            }

            LinUser linUser = await _userService.GetCurrentUserAsync();

            if (linUser == null)
            {
                messageBoard.Avatar = "/assets/user/" + new Random().Next(1, 360) + ".png";
            }
            else
            {
                messageBoard.Avatar = _currentUser.GetFileUrl(linUser.Avatar);
            }

            await _messageBoardRepository.InsertAsync(messageBoard);
        }
コード例 #3
0
        public async Task <UnifyResponseDto> CreateAsync([FromBody] CreateMessageBoardDto createMessageBoardDto)
        {
            await _messageBoardService.CreateAsync(createMessageBoardDto);

            return(UnifyResponseDto.Success("留言成功"));
        }