Пример #1
0
        public async Task <IActionResult> UpdateQuestion(int id, [FromBody] UpdateQuestionModel model)
        {
            if (model == null || model.ID != id)
            {
                return(BadRequest());
            }

            var q = await _QuestionRepository.Get(id);

            if (q == null)
            {
                return(NotFound());
            }

            q.ID    = model.ID;
            q.Title = model.Title;
            q.Body  = model.Body;
            //q.ClosedDate = model.ClosedDate;
            q.Score            = model.Score;
            q.AcceptedAnswerID = model.AcceptedAnswerID;

            await _QuestionRepository.Update(q);

            return(Ok());
        }
Пример #2
0
        public IActionResult EditQuestion(string id, [FromBody] UpdateQuestionModel model)
        {
            var question = context.Questions.ToList().Single(q => q.Id.ToString() == id);

            question.Text = model.QuestionText;
            foreach (var answer in model.Answers
                     .Where(answer => answer.Id.ToString() == model.CorrectId))
            {
                answer.IsCorrect = true;
            }

            question.Answers = model.Answers;
            context.Questions.Update(question);
            context.SaveChanges();

            return(new JsonResult(new
            {
                success = true,
                description = "question updated"
            }));
        }
Пример #3
0
        //new Question(0, questionModel.Title, questionModel.Answers);

        public static Question ConvertToQuestionEntity(this UpdateQuestionModel questionModel) =>
        new Question(questionModel.Id, questionModel.Title, new List <Answer>());