public async Task<ApiResult<QuestionDTO>> UpdateQuestionAsync(QuestionDTO question)
 {
     var path = $"/questions/{question.Id}";
     var response = await _httpClient.SendRequestWithBearerTokenAsync(HttpMethod.Put, path, question,
                 await _surveysTokenService.GetTokenForWebApiAsync(_httpContextAccessor.HttpContext.User)
                         .ConfigureAwait(false), _cancellationToken);
     return await ApiResult<QuestionDTO>.FromResponseAsync(response).ConfigureAwait(false);
 }
        public async Task<IActionResult> Create(QuestionDTO question)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var result = await _questionService.CreateQuestionAsync(question);
                    if (result.Succeeded)
                    {
                        return RedirectToAction("Edit", "Survey", new { id = question.SurveyId });
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, $"Unable to create question. (HTTP {result.StatusCode})");
                        switch (result.StatusCode)
                        {
                            case (int)HttpStatusCode.Unauthorized:
                                return ReAuthenticateUser();
                            case (int)HttpStatusCode.Forbidden:
                                ViewBag.Forbidden = true;
                                return View(question);
                            default:
                                return View(question);
                        }
                    }
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Bad Request");
                    return View(question);
                }
            }
            catch (AuthenticationException)
            {
                return ReAuthenticateUser();
            }
            catch
            {
                // Errors have been logged by QuestionService. Swallowing exception to stay on same page to display error.
                ViewBag.Message = "Unexpected Error";
            }

            return View("~/Views/Shared/Error.cshtml");
        }
 /// <summary>
 /// This action provides the Http Get experience for creating a <see cref="Tailspin.Surveys.Data.DataModels.Question"/> in the context of a <see cref="Tailspin.Surveys.Data.DataModels.Survey"/>.
 /// </summary>
 /// <param name="id">The id of a <see cref="Tailspin.Surveys.Data.DataModels.Survey"/></param>
 /// <returns>A view with form fields for a new <see cref="Tailspin.Surveys.Data.DataModels.Question"/></returns>
 public IActionResult Create(int id)
 {
     var question = new QuestionDTO { SurveyId = id };
     return View(question);
 }