Пример #1
0
        public async Task <AnswerSurveyResponseDto> AnswerAsync([FromBody] AnswerSurveyDto answer)
        {
            Survey tempSurvey = new Survey(null, answer);

            User tempUser = new User
            {
                Id = answer.UserId
            };

            AnswerSurveyResponseDto response = await _repository.AnswerSurveyAsync(tempSurvey, tempUser);

            return(response);
        }
Пример #2
0
        public async Task <AnswerSurveyResponseDto> AnswerSurveyAsync(Survey survey, User user)
        {
            AnswerSurveyResponseDto response = new AnswerSurveyResponseDto();

            using (SqlConnection connection = await _dbContext.OpenConnectionAsync())
            {
                using (SqlCommand command = new SqlCommand(AnswerSurveyStatement, connection))
                {
                    command.Parameters.AddWithValue("@SurveyID", survey.Id);
                    command.Parameters.AddWithValue("@UserID", user.Id);
                    command.Parameters.AddWithValue("@Answers", JsonConvert.SerializeObject(survey.Questions));

                    int rowsAffected = await command.ExecuteNonQueryAsync();

                    if (rowsAffected == 1)
                    {
                        response.ResponseMessage = $"Your answer has been registered for the survey titled: {survey.Title}";
                    }
                }
            }

            return(response);
        }