예제 #1
0
        public async Task <IActionResult> AddQuestion(QuestionToCreateDto questionToCreate)
        {
            var newquestion = _mapper.Map <Question>(questionToCreate);

            newquestion.Category = await _repo.GetCategoryAsync(questionToCreate.CategoryId);

            newquestion.QuestionBy = await _repo.GetUserAsync(questionToCreate.QuestionerId);

            _repo.Add(newquestion);

            if (await _repo.SaveAll())
            {
                return(Ok(newquestion));
            }

            throw new Exception("Question failed to add");
        }
예제 #2
0
        public async Task <IActionResult> AddArticle(ArticleToCreateDto articleToCreate)
        {
            var newArticle = _mapper.Map <Article>(articleToCreate);

            newArticle.Category = await _repo.GetCategoryAsync(articleToCreate.CategoryId);

            newArticle.Writer = await _repo.GetUserAsync(articleToCreate.WriterId);

            _repo.Add(newArticle);

            if (await _repo.SaveAll())
            {
                return(Ok(newArticle));
            }

            throw new Exception("Article failed to add");
        }