public async Task <ActionResult> Create([Bind("Title,Body,Author,AuthorId,Answered,Inappropriate,UpVotes,DownVotes,Id,Topics")] Question newQuestion) { try { if (!ModelState.IsValid) { throw new Exception(); } try { var user = await _userManager.GetUserAsync(HttpContext.User); var question = _questionsService.CreateQuestion(newQuestion, user); return(RedirectToAction(nameof(Index))); } catch (Exception) { return(BadRequest()); } } catch { return(View(newQuestion)); } }
public ActionResult <Question> CreateQuestion([FromBody] Question newQuestion) { try { return(Ok(_ps.CreateQuestion(newQuestion))); } catch (Exception e) { return(BadRequest(e.Message)); } }
public IActionResult Create([Bind("Id,Title,Body,UserId")] Question question) { var user = _um.GetUserAsync(HttpContext.User).Result; question.UserId = user.Id; if (ModelState.IsValid) { _service.CreateQuestion(question); return(RedirectToAction(nameof(Index))); } return(View(question)); }
public IActionResult Create([FromForm] Question question) { if (!ModelState.IsValid) { throw new Exception("Question is invalid"); } var user = _userManager.GetUserAsync(HttpContext.User).Result; _service.CreateQuestion(question, user); return(View(question)); }
public async Task <IActionResult> CreateQuestion([FromBody] Question newQuestion) { try { var user = await _userManager.GetUserAsync(HttpContext.User); var question = _questionsService.CreateQuestion(newQuestion, user); return(View("", question)); } catch (Exception) { return(BadRequest()); } }
public Task <Guid> Create(CreateQuestionRequest request, [FromRoute] Guid gameId) { return(questionsService.CreateQuestion(request, gameId)); }