public RespStudentQuestions getListQuestions(RequestStudentQuestions Parametros) { RespStudentQuestions respuesta = new RespStudentQuestions(); studentCore core = new studentCore(); string mensaje = ""; int idStudent = core.validateStudent(Parametros.RQ.user_number, Parametros.RQ.user_password, ref mensaje); if (idStudent != -1) { questionsCore qCore = new questionsCore(); List <Questions> ListQuestions = qCore.getListQuestion(Parametros.RQ.ID_lesson, ref mensaje); if (ListQuestions != null && ListQuestions.Count > 0) { RespStudent Respuesta = new RespStudent(); Respuesta.code = CodigosRespuesta.codigo.OK; Respuesta.estatus = mensaje; respuesta.Response = Respuesta; respuesta.Questions = ListQuestions; } else { RespStudent Respuesta = new RespStudent(); Respuesta.code = CodigosRespuesta.codigo.NOT_FOUND; Respuesta.estatus = MensajesEstados.SIN_RESULTADOS; respuesta.Response = Respuesta; respuesta.Questions = null; } } else { RespStudent Respuesta = new RespStudent(); Respuesta.code = CodigosRespuesta.codigo.FORBIDDEN; Respuesta.estatus = MensajesEstados.ErrorAcceso; respuesta.Response = Respuesta; respuesta.Questions = null; } return(respuesta); }
protected bool parametrosValidos(RequestStudentQuestions Parametros, ref string mensaje) { bool valido = true; string mensajeParametros = "Parámetros incorrectos: "; if (Parametros.RQ.user_number == null || Parametros.RQ.user_number.Trim() == "") { mensajeParametros += "user_number "; valido = false; } if (Parametros.RQ.user_password == null || Parametros.RQ.user_password.Trim() == "") { mensajeParametros += "user_password "; valido = false; } if (Parametros.RQ.ID_lesson == null) { mensajeParametros += "ID_lesson "; valido = false; } mensaje = mensajeParametros; return(valido); }
public String getListQuestions() { String JSON; try { Response.ContentType = "application/json; charset=UTF-8"; String metodoDeEnvioHTTP = System.Web.HttpContext.Current.Request.HttpMethod; if (metodoDeEnvioHTTP != "POST") { RespStudent Respuesta = new RespStudent(); Respuesta.code = CodigosRespuesta.codigo.INTERNAL_SERVER_ERROR; Respuesta.estatus = MensajesEstados.ERROR_POST_REQUEST; JSON = JsonConvert.SerializeObject(new ResponseStudentQuestions(Respuesta, null)); } else { string POST; using (Stream receiveStream = Request.InputStream) { using (StreamReader readStream = new StreamReader(receiveStream, Request.ContentEncoding)) { POST = readStream.ReadToEnd(); } } if (POST == null || POST == "") { RespStudent Respuesta = new RespStudent(); Respuesta.code = CodigosRespuesta.codigo.INTERNAL_SERVER_ERROR; Respuesta.estatus = MensajesEstados.ErrorFatal; JSON = JsonConvert.SerializeObject(new ResponseStudentQuestions(Respuesta, null)); } else { RequestStudentQuestions Parametros = JsonConvert.DeserializeObject <RequestStudentQuestions>(POST); string Mensaje = ""; if (parametrosValidos(Parametros, ref Mensaje)) { ADStudent coursesAD = new ADStudent(); RespStudentQuestions Respuesta = coursesAD.getListQuestions(Parametros); JSON = JsonConvert.SerializeObject(new ResponseStudentQuestions(Respuesta.Response, Respuesta.Questions)); } else { RespStudent Respuesta = new RespStudent(); Respuesta.estatus = Mensaje; Respuesta.code = CodigosRespuesta.codigo.BAD_REQUEST; JSON = JsonConvert.SerializeObject(new ResponseStudentQuestions(Respuesta, null)); } } } } catch (Exception e) { RespStudent Respuesta = new RespStudent(); Respuesta.estatus = MensajesEstados.ErrorFatal + e.Message.ToString(); Respuesta.code = CodigosRespuesta.codigo.INTERNAL_SERVER_ERROR; JSON = JsonConvert.SerializeObject(new ResponseStudentQuestions(Respuesta, null)); } return(JSON); }