예제 #1
0
        PostAnswer(AnswerPostFullRequest answerPostRequest)
        {
            var questionExists = _dataRepository.QuestionExists(answerPostRequest.QuestionId.Value);

            if (!questionExists)
            {
                return(NotFound());
            }

            var savedAnswer =
                _dataRepository.PostAnswer(new AnswerPostFullRequest
            {
                QuestionId = answerPostRequest.QuestionId.Value,
                Content    = answerPostRequest.Content,
                UserId     = User.FindFirst(ClaimTypes.NameIdentifier).Value,
                UserName   = await GetUserName(),
                Created    = DateTime.UtcNow
            }
                                           );

            _cache.Remove(answerPostRequest.QuestionId.Value);

            await _questionHubContext.Clients.Group($"Question-{answerPostRequest.QuestionId.Value}")
            .SendAsync("ReceiveQuestion", _dataRepository.GetQuestion(answerPostRequest.QuestionId.Value));

            return(savedAnswer);
        }
예제 #2
0
        public async Task <AnswerGetResponse> PostAnswer(AnswerPostFullRequest answer)
        {
            await using var connection = new SqlConnection(_connectionString);
            await connection.OpenAsync();

            return(await connection.QueryFirstAsync <AnswerGetResponse>(
                       @"exec dbo.Answer_Post @QuestionId = @QuestionId, @Content = @Content, 
                    @UserId = @UserId, @UserName = @UserName,
                    @Created = @Created", answer));
        }
예제 #3
0
 public AnswerGetResponse PostAnswer(AnswerPostFullRequest answer)
 {
     using (var connection = new SqlConnection(_connectionString))
     {
         connection.Open();
         return(connection.QueryFirst <AnswerGetResponse>(
                    @"EXEC dbo.Answer_Post @QuestionId = @QuestionId, @Content = @Content, @UserId = @UserId, @UserName = @UserName, @Created = @Created",
                    answer
                    ));
     }
 }