public async Task <IActionResult> SeeQuestion(string id) { var question = await this.questionsService.GetQuestionDetailsAsync <SeeQuestionViewModel>(id); var model = new CreateAnswerInputModel() { Question = question, }; return(this.View(model)); }
public async Task <IActionResult> Create(CreateAnswerInputModel input) { if (!this.ModelState.IsValid) { return(this.View(input)); } var answerId = await this.answersService.CreateAsync(input.Title, input.Content, input.Question.StylistId, input.Question.ClientId, input.Question.Id); this.TempData["InfoMessage"] = GlobalMessages.SuccessSendMessage; return(this.RedirectToAction(nameof(this.SeeDetails), new { Id = answerId })); }
public async Task <IActionResult> Create(CreateAnswerInputModel input) { if (input.AnswerId == null || input.AnswerId == "" || input.PostId == null || input.PostId == "") { return(BadRequest("")); } string userId = User.Claims.First(x => x.Type == ClaimTypes.NameIdentifier).Value; var user = await _httpSender.SendGetAsync <GetUserResponse>(UsersController.UsersRoot + "?id=" + userId); CreateAnswerModel answer = new CreateAnswerModel { Text = input.Text, AuthorId = userId, AuthorName = user.Name, AnswerId = input.AnswerId, PostId = input.PostId }; Response response = new Response(); try { response = await _httpSender.SendPostAsync <Response, CreateAnswerModel>(answer, AnswersRoot); } catch (Exception e) { return(StatusCode(500)); } if (response.Status == Status.Ok) { return(Ok()); } else if (response.Status == Status.ServerError) { return(StatusCode(500, response.Error)); } else { return(BadRequest(response.Error)); } }