public ActionResult Update(ExamQuestionDTO dto)
        {
            if (dto.RightAnswer == null || dto.RightAnswer.Length <= 0)
            {
                return(Json(OperationResult.Error("请勾选正确答案")));
            }
            if (dto.RightAnswer.Any(s => string.IsNullOrWhiteSpace(s)))
            {
                return(Json(OperationResult.Error("请勾选正确答案")));
            }

            var entity = _examContract.Entities.Where(e => !e.IsDeleted && e.IsEnabled && e.Id == dto.Id).FirstOrDefault();

            entity.Title = dto.Title;
            entity.Score = dto.Score;
            if (!string.IsNullOrEmpty(dto.ImgUrl) && dto.ImgUrl.IndexOf("base64") > 0)
            {
                entity.ImgUrl = SaveImg(dto.ImgUrl);
            }
            dto.AnswerOptions.ForEach(o =>
            {
                if (!string.IsNullOrEmpty(o.ImgUrl) && o.ImgUrl.IndexOf("base64") > 0)
                {
                    o.ImgUrl = SaveImg(o.ImgUrl);
                }
            });
            entity.AnswerOptions = JsonHelper.ToJson(dto.AnswerOptions);
            entity.RightAnswer   = string.Join(",", dto.RightAnswer);

            var result = _examContract.Update(new ExamQuestionEntity[] { entity });


            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public IHttpActionResult PostExam_Question(ExamQuestionDTO examQuestionDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Exam_Question exam_Question = new Exam_Question();

            exam_Question.ExamID         = examQuestionDTO.ExamID;
            exam_Question.QuestionID     = examQuestionDTO.QuestionID;
            exam_Question.QuestionNumber = examQuestionDTO.QuestionNumber;
            db.Exam_Question.Add(exam_Question);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = exam_Question.ID }, exam_Question));
        }
        public IHttpActionResult PutExam_Question(int id, ExamQuestionDTO examQuestionDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != examQuestionDTO.ID)
            {
                return(BadRequest());
            }

            Exam_Question exam_Question = db.Exam_Question.Find(id);

            exam_Question.QuestionID     = examQuestionDTO.QuestionID;
            exam_Question.ExamID         = examQuestionDTO.ExamID;
            exam_Question.QuestionNumber = 0;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!Exam_QuestionExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }