public JsonResult DeleteMCQ(int QuestionID) { bool statusFlag = false; var ErrorDictionary = new Dictionary <string, string>(); LoginUserDetails objLoginUserDetails = null; MCQ_QUESTION_DTO objMCQ_QUESTION_DTO = new MCQ_QUESTION_DTO(); objMCQ_QUESTION_DTO.QuestionID = QuestionID; try { objLoginUserDetails = (LoginUserDetails)InsiderTrading.Common.Common.GetSessionValue((string)ConstEnum.SessionValue.UserDetails); using (var objMCQSL = new MCQSL()) { objMCQ_QUESTION_DTO = objMCQSL.InsertUpdateMCQQuestionDetails(objLoginUserDetails.CompanyDBConnectionString, objMCQ_QUESTION_DTO, null, "DELETE"); } statusFlag = true; ErrorDictionary.Add("success", Common.Common.getResource("usr_msg_54105")); // Details Deleted Sucessfully } catch (Exception exp) { statusFlag = false; ModelState.Remove("KEY"); ModelState.Add("KEY", new ModelState()); ModelState.Clear(); string sErrMessage = Common.Common.getResource(exp.InnerException.Data[0].ToString()); ModelState.AddModelError("error", sErrMessage); ErrorDictionary = GetModelStateErrorsAsString(); } finally { objLoginUserDetails = null; } return(Json(new { status = statusFlag, Message = ErrorDictionary }, JsonRequestBehavior.AllowGet)); }
public ActionResult MCQ_User(int acid, List <MCQQuestionModel> objMCQQuestionModel, int AttemptNo = 0) { bool statusFlag = false; var ErrorDictionary = new Dictionary <string, string>(); try { objLoginUserDetails = (LoginUserDetails)InsiderTrading.Common.Common.GetSessionValue((string)ConstEnum.SessionValue.UserDetails); objMCQ_QUESTION_DTO = new MCQ_QUESTION_DTO(); DataTable dt = ConvertListTODataTable(objMCQQuestionModel, null); if (dt != null) { if (dt.Rows.Count > 0) { objMCQ_QUESTION_DTO.UserinfoID = objLoginUserDetails.LoggedInUserID; objMCQ_QUESTION_DTO.AttemptNo = AttemptNo; using (var objMCQSL = new MCQSL()) { objMCQ_QUESTION_DTO = objMCQSL.InsertUpdateMCQQuestionDetails(objLoginUserDetails.CompanyDBConnectionString, objMCQ_QUESTION_DTO, dt, "SAVE_EXAM_RESULT"); statusFlag = true; ErrorDictionary.Add("success", Common.Common.getResource("usr_msg_54121")); } using (var objMCQSL = new MCQSL()) { objMCQ_QUESTION_DTO = objMCQSL.GetMCQQuestionDetails(objLoginUserDetails.CompanyDBConnectionString, 0, "ValidateUserSettings", out msg, objLoginUserDetails.LoggedInUserID); ViewBag.UserMessage = objMCQ_QUESTION_DTO.UserMessage; ViewBag.AttemptMessage = objMCQ_QUESTION_DTO.AttemptMessage; } } else { statusFlag = false; ErrorDictionary.Add("Error", Common.Common.getResource("usr_msg_54138")); return(Json(new { status = statusFlag, Message = ErrorDictionary, SuccessMessage = "", AttmptMessage = "", NextAttempt = 0, TotalAttempts = 0, ResultDuringFrequency = "" }, JsonRequestBehavior.AllowGet)); } } else { statusFlag = false; ErrorDictionary.Add("Error", Common.Common.getResource("usr_msg_54138")); return(Json(new { status = statusFlag, Message = ErrorDictionary, SuccessMessage = "", AttmptMessage = "", NextAttempt = 0, TotalAttempts = 0, ResultDuringFrequency = "" }, JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { statusFlag = false; ErrorDictionary.Add("Error", ex.ToString()); return(Json(new { status = statusFlag, Message = ErrorDictionary, SuccessMessage = "", AttmptMessage = "", NextAttempt = 0, TotalAttempts = 0, ResultDuringFrequency = "" }, JsonRequestBehavior.AllowGet)); } return(Json(new { status = statusFlag, Message = ErrorDictionary, SuccessMessage = objMCQ_QUESTION_DTO.UserMessage, AttmptMessage = objMCQ_QUESTION_DTO.AttemptMessage, NextAttempt = objMCQ_QUESTION_DTO.AttemptNo, TotalAttempts = objMCQ_QUESTION_DTO.TotalAttempts, ResultDuringFrequency = objMCQ_QUESTION_DTO.ResultDuringFrequency.Trim() }, JsonRequestBehavior.AllowGet)); }
public ActionResult MCQQuestions(List <MCQQuestionModel> objMCQQuestionModel, MCQModel objMCQModel, int acid = 0, List <int> objOptionIDLIst = null, int formId = 0) { bool statusFlag = true; bool EmptyRows = false; bool IsAlphaNumeric = false; bool IsSpcialCharacter = false; var ErrorDictionary = new Dictionary <string, string>(); System.Text.RegularExpressions.Regex aLphaNumeric = new System.Text.RegularExpressions.Regex(@"^[a-zA-Z0-9_ ]*$"); objLoginUserDetails = (LoginUserDetails)InsiderTrading.Common.Common.GetSessionValue((string)ConstEnum.SessionValue.UserDetails); int counter = 0; try { if (objMCQQuestionModel != null) { foreach (var questionAnswer in objMCQQuestionModel.Skip(1)) { if (counter != 0) { if (questionAnswer.QuestionsAnswer == null) { statusFlag = false; if (ErrorDictionary.ContainsKey("Error")) { break; } else { ErrorDictionary.Add("Error", Common.Common.getResource("usr_msg_54150")); EmptyRows = true; } } } if (questionAnswer.QuestionsAnswer != null) { if (!aLphaNumeric.IsMatch(questionAnswer.QuestionsAnswer)) { if (!IsAlphaNumeric) { if (ErrorDictionary.ContainsKey("Error")) { ErrorDictionary["Error"] += "<li>" + Common.Common.getResource("usr_msg_54151") + "</li>"; } else { ErrorDictionary.Add("Error", Common.Common.getResource("usr_msg_54151")); EmptyRows = true; } IsAlphaNumeric = true; } } } counter = counter + 1; } DataTable dt = ConvertListTODataTable(objMCQQuestionModel.GroupBy(i => i.QuestionsAnswer).Select(g => g.First()).ToList(), objOptionIDLIst); DataRow[] rows; rows = dt.Select("CorrectAnswer = 'True'"); if (dt.Rows.Count != objMCQModel.Option_number) { statusFlag = false; if (!EmptyRows) { var anyDuplicate = objMCQQuestionModel.Where(x => x.QuestionsAnswer != null).GroupBy(x => x.QuestionsAnswer).Any(g => g.Count() > 1); if (anyDuplicate) { if (ErrorDictionary.ContainsKey("Error")) { ErrorDictionary["Error"] += "<li>" + Common.Common.getResource("usr_msg_54147") + "</li>"; } else { ErrorDictionary.Add("Error", Common.Common.getResource("usr_msg_54147")); } } } } if (rows.Length == 0 && dt != null && dt.Rows.Count > 0) { statusFlag = false; if (ErrorDictionary.ContainsKey("Error")) { ErrorDictionary["Error"] += "<li>" + Common.Common.getResource("usr_msg_54148") + "</li>"; } else { ErrorDictionary.Add("Error", Common.Common.getResource("usr_msg_54148")); } } if (string.IsNullOrEmpty(objMCQModel.Question)) { statusFlag = false; if (ErrorDictionary.ContainsKey("Error")) { ErrorDictionary["Error"] += "<li>" + Common.Common.getResource("usr_msg_54152") + "</li>"; } else { ErrorDictionary.Add("Error", Common.Common.getResource("usr_msg_54152")); } } if (objMCQModel.Answer_Type == null) { if (ErrorDictionary.ContainsKey("Error")) { ErrorDictionary["Error"] += "<li>" + Common.Common.getResource("usr_msg_54155") + "</li>"; } else { ErrorDictionary.Add("Error", Common.Common.getResource("usr_msg_54155")); } } if (objMCQModel.Option_number == 0) { if (ErrorDictionary.ContainsKey("Error")) { ErrorDictionary["Error"] += "<li>" + Common.Common.getResource("usr_msg_54156") + "</li>"; } else { ErrorDictionary.Add("Error", Common.Common.getResource("usr_msg_54156")); } } if (statusFlag) { if (objMCQModel.QuestionID != 0) { using (var objMCQSL = new MCQSL()) { objMCQ_QUESTION_DTO = objMCQSL.GetMCQQuestionDetails(objLoginUserDetails.CompanyDBConnectionString, objMCQModel.QuestionID, "SELECT", out msg, objLoginUserDetails.LoggedInUserID); } } if (objMCQ_QUESTION_DTO != null) { InsiderTrading.Common.Common.CopyObjectPropertyByNameAndActivity(objMCQModel, objMCQ_QUESTION_DTO); objMCQModel.Flag = "UPDATE"; } else { objMCQ_QUESTION_DTO = new MCQ_QUESTION_DTO(); objMCQModel.Flag = "INSERT"; } objMCQ_QUESTION_DTO.Question = objMCQModel.Question; objMCQ_QUESTION_DTO.AnswerTypes = (objMCQModel.Answer_Type == "Radio") ? 1 : 2; objMCQ_QUESTION_DTO.OptionNumbers = objMCQModel.Option_number; objMCQ_QUESTION_DTO.UserinfoID = objLoginUserDetails.LoggedInUserID; using (var objMCQSL = new MCQSL()) { objMCQ_QUESTION_DTO = objMCQSL.InsertUpdateMCQQuestionDetails(objLoginUserDetails.CompanyDBConnectionString, objMCQ_QUESTION_DTO, dt, objMCQModel.Flag); } statusFlag = true; ErrorDictionary.Add("success", Common.Common.getResource("usr_msg_54106")); // PopulateCombo(); } } else { statusFlag = false; if (objMCQModel.Answer_Type == null) { if (ErrorDictionary.ContainsKey("Error")) { ErrorDictionary["Error"] += "<li>" + Common.Common.getResource("usr_msg_54155") + "</li>"; } else { ErrorDictionary.Add("Error", Common.Common.getResource("usr_msg_54155")); } } if (objMCQModel.Option_number == 0) { if (ErrorDictionary.ContainsKey("Error")) { ErrorDictionary["Error"] += "<li>" + Common.Common.getResource("usr_msg_54156") + "</li>"; } else { ErrorDictionary.Add("Error", Common.Common.getResource("usr_msg_54156")); } } if (objMCQModel.Question == null) { if (ErrorDictionary.ContainsKey("Error")) { ErrorDictionary["Error"] += "<li>" + Common.Common.getResource("usr_msg_54152") + "</li>"; } else { ErrorDictionary.Add("Error", Common.Common.getResource("usr_msg_54152")); } } } } catch (Exception ex) { statusFlag = false; ErrorDictionary.Add("Error", Common.Common.getResource("usr_msg_54137")); } return(Json(new { status = statusFlag, Message = ErrorDictionary }, JsonRequestBehavior.AllowGet)); }