public static IEnumerable <AutoEvQuestionScoreViewModel> GetQuestions(int codCargoEvaluador, int codCargoEvaluado, int numEval, int codProc, string sectionCode) { List <AutoEvQuestionScoreViewModel> RandomQ = new List <AutoEvQuestionScoreViewModel>(); string CnnStr = ConfigurationManager.ConnectionStrings["CnnStr"].ConnectionString; string sql = "select epc.Numero_Pregunta, pal.Texto_Pregunta, epc.Numero_Evaluacion " + "from Evaluacion_Preguntas_Cargos epc " + "Join Evaluaciones_Cargos evc on epc.Numero_Evaluacion = evc.Numero_Evaluacion " + " and epc.Codigo_Proceso = evc.Codigo_Proceso and epc.Codigo_Usuario = evc.Cod_Usuario_Evaluado " + "join Preguntas_Cargos pca on evc.Cod_Cargo_Evaluado = pca.Cod_Cargo_Evaluado and epc.Codigo_seccion = pca.Codigo_seccion " + "and epc.Numero_Pregunta = pca.Numero_Pregunta " + "join Preguntas_Aleatorias pal on epc.Codigo_seccion = pal.Codigo_Seccion and epc.Numero_Pregunta = pal.Numero_Pregunta " + "Where pca.Codigo_Cargo = " + codCargoEvaluador + " And pca.Cod_Cargo_Evaluado = " + codCargoEvaluado + " And evc.Codigo_Proceso = '" + codProc + "' " + " And epc.Numero_Evaluacion = " + numEval + " And epc.Codigo_seccion = '" + sectionCode + "' " + " And pca.Cod_Cargo_Evaluado <> pca.Codigo_Cargo "; using SqlConnection Cnn = new SqlConnection(CnnStr); using SqlCommand cmd = new SqlCommand { CommandText = sql, Connection = Cnn }; Cnn.Open(); using SqlDataReader sec = cmd.ExecuteReader(); if (sec.HasRows) { try { while (sec.Read()) { AutoEvQuestionScoreViewModel scc = new AutoEvQuestionScoreViewModel() { Codigo_Seccion = sectionCode, Numero_Pregunta = sec.GetInt32(0), Texto_Pregunta = sec.GetString(1), }; RandomQ.Add(scc); } } catch (Exception ex) { string mensaje = ex.InnerException.InnerException.Message; RandomQ.Add(new AutoEvQuestionScoreViewModel() { Codigo_Seccion = "Error", Texto_Pregunta = mensaje + " Valide la información" }); } } return(RandomQ); }
public static IEnumerable <AutoEvQuestionScoreViewModel> QuestionsByUser(int numEval, int codProc, string sectionCode) { List <AutoEvQuestionScoreViewModel> RandomQ = new List <AutoEvQuestionScoreViewModel>(); string CnnStr = ConfigurationManager.ConnectionStrings["CnnStr"].ConnectionString; string sql = "select distinct aep.Numero_Pregunta, pal.Texto_Pregunta, aep.Nota " + "from Preguntas_Cargos pec " + "join Auto_Evaluacion_Preguntas aep on pec.Codigo_seccion = aep.Codigo_seccion " + "join Auto_Evaluaciones aev on aep.Numero_Evaluacion = aev.Numero_Evaluacion and aep.Codigo_Proceso = aev.Codigo_Proceso " + "join Preguntas_Aleatorias pal on aep.Codigo_seccion = pal.Codigo_Seccion and aep.Numero_Pregunta = pal.Numero_Pregunta " + "where aep.Numero_Evaluacion = " + numEval + " and aep.Codigo_Proceso = " + codProc + " and aep.Codigo_seccion = '" + sectionCode + "'" + " And pec.Cod_Cargo_Evaluado = pec.Codigo_Cargo And aep.Nota = 0"; using SqlConnection Cnn = new SqlConnection(CnnStr); using SqlCommand cmd = new SqlCommand { CommandText = sql, Connection = Cnn }; Cnn.Open(); using SqlDataReader sec = cmd.ExecuteReader(); if (sec.HasRows) { try { while (sec.Read()) { AutoEvQuestionScoreViewModel scc = new AutoEvQuestionScoreViewModel() { Codigo_Seccion = sectionCode, Numero_Pregunta = sec.GetInt32(0), Texto_Pregunta = sec.GetString(1), Nota = sec.GetDecimal(2), }; RandomQ.Add(scc); } } catch (Exception ex) { string mensaje = ex.InnerException.InnerException.Message; RandomQ.Add(new AutoEvQuestionScoreViewModel() { Codigo_Seccion = "Error", Texto_Pregunta = mensaje + " Valide la información" }); } } else { RandomQ.Add(new AutoEvQuestionScoreViewModel() { Codigo_Seccion = "Error", Texto_Pregunta = "No hay preguntas sin responder para este Dominio, Valide la información" }); } if (RandomQ == null) { RandomQ.Clear(); RandomQ.Add(new AutoEvQuestionScoreViewModel() { Codigo_Seccion = "Error", Texto_Pregunta = "Todas las preguntas de Auto Evaluación ya fueron respondidas" }); } return(RandomQ); }