Ejemplo n.º 1
0
        public async Task <IActionResult> CreateQuestion(Question question)
        {
            if (ModelState.IsValid == false)
            {
                return(BadRequest("Invalid data"));
            }

            try
            {
                await _questionManager.CreateAsync(question);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.Message));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create(QuestionActionsViewModel model)
        {
            if (ModelState.IsValid)
            {
                var userId = await _accountManager.GetUserIdByNameAsync(User.Identity.Name);

                var questionDto = new QuestionDto
                {
                    UserId      = userId,
                    Title       = model.Title,
                    Description = model.Description,
                    Comment     = model.Comment,
                    File        = model.File,
                    Path        = model.Path,
                    Answer      = model.Answer
                };

                await _questionManager.CreateAsync(questionDto);

                return(RedirectToAction("Index", "Question"));
            }

            return(View(model));
        }