Пример #1
0
        public IActionResult CreateQuestion([FromBody] RequestCreateQuestion question)
        {
            Question entity;

            if (ModelState.IsValid)
            {
                entity = questionServices.CreateQuestion(question);
                questionServices.Commit();
                question.ToModel(entity);
                return(Created($"api/questiontypes/{entity.Id}", question));
            }
            else
            {
                return(BadRequest());
            }
        }
Пример #2
0
        public Question CreateQuestion(RequestCreateQuestion model)
        {
            var entity = model.ToEntity();

            PrepareCreate(entity);
            Question question = Add(entity);

            Commit();
            IList <Answer> listAnswer = new List <Answer>();

            foreach (var item in model.Answers)
            {
                Answer ans = answerServices.CreateAnswer(item);
                ans.QuestionId = question.Id;
                listAnswer.Add(ans);
                Commit();
            }
            question.Answers = listAnswer;
            return(question);
        }