/// <summary> /// To clone all the images in a question. /// </summary> /// <param name="questionObj"></param> public void CloneImagesForQuestion(Question questionObj) { if (!String.IsNullOrEmpty(questionObj.QuestionImageReference)) { questionObj.QuestionImageReference = CloneAttachmentToPersistent(questionObj.QuestionImageReference); } if (questionObj.AnswerOptions != null && questionObj.AnswerOptions.Count > 0) { foreach (AnswerOption item in questionObj.AnswerOptions) { if (!String.IsNullOrEmpty(item.AnswerImageReference)) { item.AnswerImageReference = CloneAttachmentToPersistent(item.AnswerImageReference); } } } }
//public bool SaveSkillStructure(string uniqueIdentifier, Dictionary<string, Question> selectQuestionOrderList) //{ // _questionDocument.SaveOrUpdate(uniqueIdentifier, selectQuestionOrderList); // return true; //} public bool SaveSkillStructure(string uniqueIdentifierUrl, List<DocumentProxy> documentProxyQuestionOrderList) { SkillSet skillSetToSave = new SkillSet {Questions = new Dictionary<string, Question>()}; List<DocumentProxy> selectQuestionTemplateList = documentProxyQuestionOrderList.Where(qusTemp => qusTemp.IsQuestionFromTemplate).ToList(); List<DocumentProxy> selectQuestionBankList = documentProxyQuestionOrderList.Where(qusTemp => !(qusTemp.IsQuestionFromTemplate)).ToList(); foreach (DocumentProxy docProxyQuestionBank in selectQuestionBankList) { if (!AppCommon.CheckIfStringIsEmptyOrNull(docProxyQuestionBank.ParentReferenceGuid)) { Question questionFromSkillSet = _questionBankService.GetQuestion(docProxyQuestionBank.Url); questionFromSkillSet.SequenceNumber = docProxyQuestionBank.OrderSequenceNumber; questionFromSkillSet.CreatedBy = docProxyQuestionBank.CreatedBy; questionFromSkillSet.CreatedTimeStamp = docProxyQuestionBank.CreatedTimeStamp; skillSetToSave.Questions.Add(docProxyQuestionBank.UniqueIdentifier, questionFromSkillSet); } else { Question question = _questionBankService.GetQuestion(docProxyQuestionBank.Url); _questionBankService.CloneImagesForQuestion(question); string newGuidQuestionBank = question.GetNewGuidValue(); question.Url = uniqueIdentifierUrl + "/Questions/" + newGuidQuestionBank; question.ParentReferenceGuid = docProxyQuestionBank.Url; question.CreatedBy = docProxyQuestionBank.CreatedBy; question.CreatedTimeStamp = docProxyQuestionBank.CreatedTimeStamp; skillSetToSave.Questions.Add(newGuidQuestionBank, question); } } foreach (DocumentProxy docProxyQuestionTemplate in selectQuestionTemplateList) { if (!AppCommon.CheckIfStringIsEmptyOrNull(docProxyQuestionTemplate.Url)) { // ----------------- step 2 already saved question -------------- Question docQusTempExist = _questionBankService.GetQuestion(docProxyQuestionTemplate.Url); docQusTempExist.SequenceNumber = docProxyQuestionTemplate.OrderSequenceNumber; docQusTempExist.CreatedBy = docProxyQuestionTemplate.CreatedBy; docQusTempExist.CreatedTimeStamp = docProxyQuestionTemplate.CreatedTimeStamp; docQusTempExist.IsAutoSave = docProxyQuestionTemplate.IsAutoSave; docQusTempExist.IsActive = docProxyQuestionTemplate.IsActive; string uniqueIdentifierAlreadySavedQuestionBank = (!String.IsNullOrEmpty(docProxyQuestionTemplate.Url) ? docProxyQuestionTemplate.Url.Split('/').Last() : String.Empty); skillSetToSave.Questions.Add(uniqueIdentifierAlreadySavedQuestionBank, docQusTempExist); } else { // ----------------- step 2 new saved question -------------- Question questionTemplate = new Question { QuestionText = docProxyQuestionTemplate.Text, QuestionType = docProxyQuestionTemplate.TypeOfQuestion, SequenceNumber = docProxyQuestionTemplate.OrderSequenceNumber, IsQuestionFromTemplate = docProxyQuestionTemplate.IsQuestionFromTemplate, TemplateSequenceNumber = docProxyQuestionTemplate.TemplateSequenceNumber, CreatedBy = docProxyQuestionTemplate.CreatedBy, CreatedTimeStamp = docProxyQuestionTemplate.CreatedTimeStamp }; string newGuidQuestion = questionTemplate.GetNewGuidValue(); questionTemplate.Url = uniqueIdentifierUrl + "/Questions/" + newGuidQuestion; skillSetToSave.Questions.Add(newGuidQuestion, questionTemplate); } } string identifierUrl = uniqueIdentifierUrl + "/Questions"; _questionDocument.SaveOrUpdate(identifierUrl, skillSetToSave.Questions); return true; }
public Question Clone() { Type type = GetType(); Question questionData = new Question(); foreach (System.Reflection.PropertyInfo objProp in type.GetProperties()) { if (objProp.PropertyType.IsGenericType) { if (objProp.Name.ToUpper() == "ANSWEROPTIONS") { List<AnswerOption> listAnswerOptionsData = new List<AnswerOption>(); if (AnswerOptions != null && AnswerOptions.Count > 0) { listAnswerOptionsData.AddRange(AnswerOptions.Select(answerOptionData => answerOptionData.Clone())); questionData.AnswerOptions = listAnswerOptionsData; } } else if (objProp.Name.ToUpper() == "CORRECTORDER") { questionData.CorrectOrder = CorrectOrder; } else { objProp.SetValue(questionData, type.GetProperty(objProp.Name).GetValue(this, null), null); } } else if (objProp.CanWrite && objProp.Name.ToUpper() != "UNIQUEIDENTIFIER" || objProp.CanWrite && objProp.Name.ToUpper() != "URL") { objProp.SetValue(questionData, type.GetProperty(objProp.Name).GetValue(this, null), null); } } return questionData; }
private string SaveQuestionsForSkillSet(Question questionItemToEdit, bool isNewQuestion, bool isExistingQuestion, string questionGuid) { if (isNewQuestion) { string questionUrlToSave = _questionBankService.FormUrlForSkillSetQuestionToQuestionBank(questionItemToEdit, GetDropBoxFromCookie()); if (questionUrlToSave != "") { _questionBankService.CloneImagesForQuestion(questionItemToEdit); SetAuditFields(questionItemToEdit, false); _questionBankService.SaveQuestion(questionItemToEdit, GetDropBoxFromCookie(), questionUrlToSave, "", true, true); } return questionUrlToSave; } if (isExistingQuestion) { if (questionItemToEdit.ParentReferenceGuid != "") { SetAuditFields(questionItemToEdit, true); Question questionItemFromQuestionBank = _questionBankService.GetQuestion(questionItemToEdit.ParentReferenceGuid); _questionBankService.CloneImagesForQuestion(questionItemToEdit); _questionBankService.DeleteImagesForQuestion(questionItemFromQuestionBank); questionItemToEdit.CreatedBy = questionItemFromQuestionBank.CreatedBy; questionItemToEdit.CreatedTimeStamp = questionItemFromQuestionBank.CreatedTimeStamp; _questionBankService.SaveQuestion(questionItemToEdit,GetDropBoxFromCookie(), questionItemToEdit.ParentReferenceGuid, "", true, true); } return questionItemToEdit.ParentReferenceGuid; } return questionItemToEdit.ParentReferenceGuid; }
/// <summary> /// To set view bags for question types based on question type. /// </summary> /// <param name="questionObject"></param> /// <param name="iQuestionType"></param> public void SetViewBagsForEditMode(Question questionObject, int iQuestionType) { try { AppEnum.QuestionTypes questioType = (AppEnum.QuestionTypes)iQuestionType; ViewBag.QuestionText = questionObject.QuestionText; ViewBag.QuestionImage = String.IsNullOrEmpty(questionObject.QuestionImageReference) ? String.Empty : questionObject.QuestionImageReference; ViewBag.CorrectAnswerRationale = questionObject.Rationale; ViewBag.LinkedCompetency = GetLinkedCompetencyForAGuid(questionObject.CompetencyReferenceGuid); ViewBag.LinkedCompetencyGuid = questionObject.CompetencyReferenceGuid; ViewBag.IsEditMode = true; ViewBag.questionTypeLoadedFlag = questionObject.QuestionType; ViewBag.BlankOrientationToLoad = questionObject.BlankOrientation; ViewBag.NoOfLabelsToLoad = questionObject.NoOfLabels; if (questionObject.AnswerOptions != null) { SetAnswerOptionsViewBagsForQuestions(questionObject.AnswerOptions); } if (questionObject.CorrectOrder != null && questionObject.CorrectOrder.Count > 0) { SetCorrectOrderViewBagsForQuestion(questionObject.CorrectOrder); } switch (questioType) { case AppEnum.QuestionTypes.CorrectOrder: break; case AppEnum.QuestionTypes.FillInTheBlank: break; case AppEnum.QuestionTypes.MultipleChoice: break; case AppEnum.QuestionTypes.ShortAnswer: break; case AppEnum.QuestionTypes.TrueFalseQuestionSetUp: break; } } catch (Exception ex) { AjaxCallResult(new AjaxResult(AppEnum.ResultType.Error, ex.ToString(), "")); ExceptionManager.Error("Error: ControllerName: QuestionBank, MethodName: SetViewBagsForEditMode", ex); } }
public ActionResult SaveQuestion(string questionUrlReference, string folderIdentifier, bool isEditMode, bool isNewQuestion, bool isExistingQuestion, string questionGuid, int authoringType, string authoringUrl, string questionNewTextToSave) { Question questionItemToEdit = new Question(); bool isProceedToStep4Valid = false; bool isQuestionSavedToQuestionBankValue = false; try { if ((isNewQuestion || isExistingQuestion) && questionNewTextToSave != "") { bool isQuestionNameExists = _questionBankService.IsQuestionNameExists(questionNewTextToSave); if (isQuestionNameExists) { return Json(new { isQuestionNameAlreadyExists = true }); } } string questionObjJson = HttpUtility.UrlDecode(new StreamReader(Request.InputStream).ReadToEnd()); string parentIdentifier = String.Empty; Question questionObject = JsonSerializer.DeserializeObject<Question>(questionObjJson); questionItemToEdit = isEditMode ? _questionBankService.GetQuestion(questionUrlReference) : questionObject; questionItemToEdit.AnswerOptions = questionObject.AnswerOptions; questionItemToEdit.BlankOrientation = questionObject.BlankOrientation; questionItemToEdit.CompetencyReferenceGuid = questionObject.CompetencyReferenceGuid; questionItemToEdit.CorrectOrder = questionObject.CorrectOrder; questionItemToEdit.NoOfLabels = questionObject.NoOfLabels; questionItemToEdit.QuestionImageReference = questionObject.QuestionImageReference; questionItemToEdit.QuestionText = questionObject.QuestionText; questionItemToEdit.QuestionType = questionObject.QuestionType; questionItemToEdit.Rationale = questionObject.Rationale; questionItemToEdit.IsActive = questionObject.IsActive; questionItemToEdit.IsAutoSave = questionObject.IsAutoSave; SetAuditFields(questionItemToEdit, isEditMode); if (authoringType == (int)AppCommon.AuthoringType.SkillSet || authoringType == (int)AppCommon.AuthoringType.AssignmentBuilder) { Question questionItemForAuthoring = questionItemToEdit.Clone(); if (isNewQuestion && !String.IsNullOrEmpty(questionNewTextToSave)) { questionItemToEdit.QuestionText = questionNewTextToSave; questionItemForAuthoring.QuestionText = questionNewTextToSave; } parentIdentifier = SaveQuestionsForSkillSet(questionItemForAuthoring, isNewQuestion, isExistingQuestion, questionGuid); if (isNewQuestion || isExistingQuestion) { isQuestionSavedToQuestionBankValue = true; } } questionItemToEdit.ParentReferenceGuid = parentIdentifier; _questionBankService.SaveQuestion(questionItemToEdit, GetDropBoxFromCookie(), questionUrlReference, folderIdentifier, isEditMode, false); if (!String.IsNullOrEmpty(authoringUrl)) { isProceedToStep4Valid = CheckIfAllQuestionsTemplatesAreConfigured(authoringUrl, authoringType); } } catch (Exception ex) { AjaxCallResult(new AjaxResult(AppEnum.ResultType.Error, ex.ToString(), "")); ExceptionManager.Error("Error: ControllerName: QuestionBank, MethodName: SaveQuestion", ex); } return Json(new { Success = "", questionResult = questionItemToEdit, isProceedToStep4Valid = isProceedToStep4Valid, isQuestionSavedToQuestionBank = isQuestionSavedToQuestionBankValue, isQuestionNameAlreadyExists = false }); }
/// <summary> /// To save Persistent image under SimApp/Attachment/Persistent /// </summary> /// <param name="isEditMode"></param> /// <param name="questionEntity"></param> /// <param name="questionUrlReference"></param> private void SavePersistentImage(bool isEditMode, Question questionEntity, string questionUrlReference) { if (!isEditMode) { string transientImage = questionEntity.QuestionImageReference; if (!String.IsNullOrEmpty(transientImage)) { string persistentImage; MoveTransientToPersistentAttachment(transientImage, out persistentImage); questionEntity.QuestionImageReference = persistentImage; } if (questionEntity.AnswerOptions != null) { foreach (AnswerOption item in questionEntity.AnswerOptions) { if (!String.IsNullOrEmpty(item.AnswerImageReference)) { string imgAnswerPersistentImage; MoveTransientToPersistentAttachment(item.AnswerImageReference, out imgAnswerPersistentImage); item.AnswerImageReference = imgAnswerPersistentImage; } } } } else { Question qnFromDb = GetQuestion(questionUrlReference); if (qnFromDb != null) { string imgUrl = CheckIfTransientImageExistsAndCreatePersistent(qnFromDb, questionEntity); questionEntity.QuestionImageReference = imgUrl; SavePersistentImageForAnswers(qnFromDb, questionEntity); } } }
/// <summary> /// To save persistent images for answers /// </summary> /// <param name="qnFromDb"></param> /// <param name="questionEntity"></param> private void SavePersistentImageForAnswers(Question qnFromDb, Question questionEntity) { string imgReference; if (questionEntity.AnswerOptions != null && questionEntity.AnswerOptions.Count > 0) { foreach (var item in questionEntity.AnswerOptions) { if (!String.IsNullOrEmpty(item.AnswerImageReference)) { CheckAndMoveTransientImages(AppEnum.AttachmentActions.CreatePersistent, string.Empty, item.AnswerImageReference, out imgReference); item.AnswerImageReference = imgReference; } } } if (qnFromDb.AnswerOptions != null && qnFromDb.AnswerOptions.Count > 0) { foreach (var item in qnFromDb.AnswerOptions) { if (!String.IsNullOrEmpty(item.AnswerImageReference)) { CheckAndMoveTransientImages(AppEnum.AttachmentActions.RemovePersistent, item.AnswerImageReference, string.Empty, out imgReference); } else { item.AnswerImageReference = String.Empty; } } } }
/// <summary> /// to set and get dynamic url for questions /// </summary> /// <param name="questionObjFromUi"></param> /// <param name="dropBox"> </param> /// <param name="questionUrl"></param> /// <param name="isEditMode"></param> /// <param name="folderIdentifier"></param> /// <returns></returns> private string FormAndSetUrlForQuestion(Question questionObjFromUi, DropBoxLink dropBox, string questionUrl, bool isEditMode, string folderIdentifier) { if (isEditMode) { return questionUrl; } if (String.IsNullOrEmpty(questionUrl)) { return string.Format(_questionDocument.GetAssignmentUrl(dropBox,DocumentPath.Module.QuestionBank,AppConstants.Create), questionUrl, questionObjFromUi.GetNewGuidValue()); } return string.Concat(questionUrl, '/', folderIdentifier, "/" + Respository.QuestionItems + "/", questionObjFromUi.GetNewGuidValue()); }
/// <summary> /// Attachment objects handler /// </summary> /// <param name="questionFromDb"></param> /// <param name="questionFromUi"></param> /// <returns></returns> private string CheckIfTransientImageExistsAndCreatePersistent(Question questionFromDb, Question questionFromUi) { string persistentImage = questionFromDb.QuestionImageReference; string transientImage = questionFromUi.QuestionImageReference; string imgUrl; bool isImageExistsInDb = !String.IsNullOrEmpty(questionFromDb.QuestionImageReference); bool isImageExistsInUi = !String.IsNullOrEmpty(questionFromUi.QuestionImageReference); AppEnum.AttachmentFlagsForStatus statusOfAttachment = GetAttachmentStatus(isImageExistsInDb, isImageExistsInUi); AppEnum.AttachmentActions attachmentActions = GetActionToPerformForAttachment(statusOfAttachment, persistentImage, transientImage); CheckAndMoveTransientImages(attachmentActions, persistentImage, transientImage, out imgUrl); return imgUrl; }
/// <summary> /// method to save a question /// </summary> /// <param name="questionObjectFromUi"> </param> /// <param name="dropBox"> </param> /// <param name="questionUrl"></param> /// <param name="folderIdentifier"></param> /// <param name="isEditMode"></param> /// <param name="isImageMovedToPersistent"> </param> /// <returns></returns> public bool SaveQuestion(Question questionObjectFromUi, DropBoxLink dropBox, string questionUrl, string folderIdentifier, bool isEditMode, bool isImageMovedToPersistent) { Question questionObject = questionObjectFromUi; //A) Set Guid referncce and Correct Url string strUrlToSave = FormAndSetUrlForQuestion(questionObject, dropBox, questionUrl, isEditMode, folderIdentifier); if (!isImageMovedToPersistent) { SavePersistentImage(isEditMode, questionObject, strUrlToSave); } _questionDocument.SaveOrUpdate(strUrlToSave, questionObject); return true; }
public string FormUrlForSkillSetQuestionToQuestionBank(Question questionItemToEdit, DropBoxLink dropBox) { return string.Format(_questionDocument.GetAssignmentUrl(dropBox,DocumentPath.Module.QuestionBank,AppConstants.Create), "", questionItemToEdit.GetNewGuidValue()); }
/// <summary> /// To delete all the images in a Question /// </summary> /// <param name="questionObj"></param> public void DeleteImagesForQuestion(Question questionObj) { if (!String.IsNullOrEmpty(questionObj.QuestionImageReference)) { RemoveAttachment(questionObj.QuestionImageReference); questionObj.QuestionImageReference = String.Empty; } if (questionObj.AnswerOptions != null && questionObj.AnswerOptions.Count > 0) { foreach (AnswerOption item in questionObj.AnswerOptions) { if (!String.IsNullOrEmpty(item.AnswerImageReference)) { RemoveAttachment(item.AnswerImageReference); item.AnswerImageReference = String.Empty; } } } }