Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }