public MultiChoiceQuestionModelCreator(string questionStr, bool isMultiplePoints = true, bool shuffleChoices = true)
 {
     _question = new MCQuestionModel
     {
         //Question = questionStr,
         TextContent      = questionStr,
         IsMultiplePoints = isMultiplePoints,
         ShuffleChoices   = shuffleChoices
     };
 }
        public HttpResponseMessage Patch([FromBody] MCQuestionModel model)
        {
            try
            {
                if (ModelState.IsValid == false || _mcQuestionSvc.UpdateQuestion(model) == false)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest));
                }

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (ServiceException ex)
            {
                return(Request.CreateResponse(ex.HttpStatusCode, ex.Message));
            }
        }
        public void AddMultiChoiceQuestion(MCQuestionModel actualQuestion, QuestionViewTypeEnum questionViewType = QuestionViewTypeEnum.Tinymce)
        {
            var question = new QuestionModel()
            {
                Id               = _qIdx,
                QuestionType     = QuestionTypeEnum.MultipleChoice,
                QuestionId       = _qIdx,
                QuestionViewType = questionViewType
            };

            actualQuestion.Id = _qIdx;
            _model.Questions.Add(question);
            _model.MultiChoiceQuestions.Add(actualQuestion);

            _qIdx++;
        }
        private bool CreateQuestion(MCQuestionModel model)
        {
            var entity = MappingUtil.Map <MCQuestionModel, MultipleChoiceQuestion>(model);

            entity.AuthorId = _currentUser.Id;
            entity.Question = "";

            if (entity.AddContentType == AddContentTypeEnum.PictureOnly)
            {
                string tmpString;
                ImageUtil.SaveImage("Test_" + model.TestId.ToString(), model.NewImageFileName, "", model.ImageContent, out tmpString);
                entity.ImageUrl = tmpString;
            }

            _uow.MultipleChoiceQuestions.Add(entity);
            _uow.SaveChanges();

            MappingUtil.Map(entity, model);
            model.Question = model.TextContent;

            return(true);
        }
        public QuestionModel CreateQuestion(object model)
        {
            QuestionModel   questionModel = null;
            MCQuestionModel actualModel   = JsonConvert.DeserializeObject <MCQuestionModel>(model.ToString());

            if (actualModel != null)
            {
                if (CreateQuestion(actualModel) == true)
                {
                    questionModel = new QuestionModel()
                    {
                        Id           = actualModel.Id,
                        QuestionId   = actualModel.Id,
                        QuestionType = QuestionTypeEnum.MultipleChoice,
                        Question     = actualModel.Question,
                        TestId       = actualModel.TestId
                    };
                }
            }

            return(questionModel);
        }
        public bool UpdateQuestion(MCQuestionModel model)
        {
            try
            {
                var entity = MappingUtil.Map <MCQuestionModel, MultipleChoiceQuestion>(model);
                entity.Choices = null;

                if (entity.AddContentType == AddContentTypeEnum.PictureOnly && model.IsImageChanged)
                {
                    string tmpString;
                    ImageUtil.SaveImage("Test_" + model.TestId.ToString(), model.NewImageFileName, "", model.ImageContent, out tmpString, true);
                    entity.ImageUrl = tmpString;
                }

                _uow.MultipleChoiceQuestions.Update(entity);
                _uow.SaveChanges();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }