private bool CreateQuestion(QAQuestionModel model) { try { var entity = MappingUtil.Map <QAQuestionModel, QandAQuestion>(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.QandAQuestions.Add(entity); _uow.SaveChanges(); MappingUtil.Map(entity, model); model.Question = model.TextContent; return(true); } catch (Exception ex) { _svcContainer.LoggingSvc.Log(ex); return(false); } }
public bool UpdateQuestion(QAQuestionModel model) { try { var entity = MappingUtil.Map <QAQuestionModel, QandAQuestion>(model); entity.Answers = 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.QandAQuestions.Update(entity); _uow.SaveChanges(); return(true); } catch (Exception ex) { _svcContainer.LoggingSvc.Log(ex); return(false); } }
public QandQuestionModelCreator(string questionStr, bool answersInOrder = false, bool isMultiPoints = true) { _question = new QAQuestionModel() { TextContent = questionStr, //Question = questionStr, AnswersInOrder = answersInOrder, IsMultiplePoints = isMultiPoints }; }
public void UpdateModel(QAQuestionModel model) { if (model.Question != null && model.Question.Length != 0) { model.TextContent = model.Question; model.Question = ""; var entity = _uow.QandAQuestions.GetById(model.Id); entity.TextContent = model.TextContent; entity.Question = ""; _uow.QandAQuestions.Update(entity); _uow.SaveChanges(); } }
public void AddQandAQuestion(QAQuestionModel actualQuestion, QuestionViewTypeEnum questionViewType = QuestionViewTypeEnum.Tinymce) { var question = new QuestionModel() { Id = _qIdx, QuestionType = QuestionTypeEnum.QandA, QuestionId = _qIdx, QuestionViewType = questionViewType }; actualQuestion.Id = _qIdx; _model.Questions.Add(question); _model.QandAQuestions.Add(actualQuestion); _qIdx++; }
public HttpResponseMessage Patch([FromBody] QAQuestionModel model) { try { if (ModelState.IsValid == false || _qaQuestionSvc.UpdateQuestion(model) == false) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } return(Request.CreateResponse(HttpStatusCode.OK)); } catch (ServiceException ex) { return(Request.CreateResponse(ex.HttpStatusCode, ex.Message)); } }
public QAQuestionModel GetQuestionById(int id) { QAQuestionModel model = null; var entity = _uow.QandAQuestions.GetAll() .Include(q => q.Answers) .Where(q => q.Id == id) .FirstOrDefault(); if (entity != null) { model = MappingUtil.Map <QandAQuestion, QAQuestionModel>(entity); } UpdateModel(model); return(model); }
public QuestionModel CreateQuestion(object model) { QuestionModel questionModel = null; QAQuestionModel actualModel = JsonConvert.DeserializeObject <QAQuestionModel>(model.ToString()); if (actualModel != null) { if (CreateQuestion(actualModel) == true) { questionModel = new QuestionModel() { Id = actualModel.Id, QuestionId = actualModel.Id, QuestionType = QuestionTypeEnum.QandA, Question = actualModel.Question, TestId = actualModel.TestId }; } } return(questionModel); }