コード例 #1
0
        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));
            }
        }
コード例 #2
0
 public ActionResult <Question> CreateQuestion([FromBody] Question newQuestion)
 {
     try
     {
         return(Ok(_ps.CreateQuestion(newQuestion)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
コード例 #3
0
        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));
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        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());
            }
        }
コード例 #6
0
 public Task <Guid> Create(CreateQuestionRequest request, [FromRoute] Guid gameId)
 {
     return(questionsService.CreateQuestion(request, gameId));
 }