Beispiel #1
0
        public RespStudentCourse addCourse(RequestStudentCourse Parametros)
        {
            RespStudentCourse respuesta = new RespStudentCourse();
            studentCore       core      = new studentCore();
            string            mensaje   = "";
            int idStudent = core.validateStudent(Parametros.RQ.user_number, Parametros.RQ.user_password, ref mensaje);

            if (idStudent != -1)
            {
                bool Correcto = core.addCourse(Parametros.RQ.ID_Course, idStudent, ref mensaje);
                if (Correcto)
                {
                    RespStudent Respuesta = new RespStudent();
                    Respuesta.code     = CodigosRespuesta.codigo.OK;
                    Respuesta.estatus  = mensaje;
                    respuesta.Response = Respuesta;
                }
                else
                {
                    RespStudent Respuesta = new RespStudent();
                    Respuesta.code     = CodigosRespuesta.codigo.INTERNAL_SERVER_ERROR;
                    Respuesta.estatus  = mensaje;
                    respuesta.Response = Respuesta;
                }
            }
            else
            {
                RespStudent Respuesta = new RespStudent();
                Respuesta.code     = CodigosRespuesta.codigo.FORBIDDEN;
                Respuesta.estatus  = MensajesEstados.ErrorAcceso;
                respuesta.Response = Respuesta;
            }
            return(respuesta);
        }
Beispiel #2
0
        public RespStudentLessons getListLessons(RequestStudentLessons Parametros)
        {
            RespStudentLessons respuesta = new RespStudentLessons();
            studentCore        core      = new studentCore();
            string             mensaje   = "";
            int idStudent = core.validateStudent(Parametros.RQ.user_number, Parametros.RQ.user_password, ref mensaje);

            if (idStudent != -1)
            {
                List <Lesson> ListLessons = new List <Lesson>();
                ListLessons = core.getListLesson(idStudent, Parametros.RQ.ID_course, ref mensaje);
                if (ListLessons != null && ListLessons.Count > 0)
                {
                    RespStudent Respuesta = new RespStudent();
                    Respuesta.code    = CodigosRespuesta.codigo.OK;
                    Respuesta.estatus = mensaje;

                    respuesta.Response = Respuesta;
                    respuesta.Lessons  = ListLessons;
                }
                else
                {
                    RespStudent Respuesta = new RespStudent();
                    Respuesta.code    = CodigosRespuesta.codigo.NOT_FOUND;
                    Respuesta.estatus = MensajesEstados.SIN_RESULTADOS;

                    respuesta.Response = Respuesta;
                    respuesta.Lessons  = null;
                }
            }
            else
            {
                RespStudent Respuesta = new RespStudent();
                Respuesta.code    = CodigosRespuesta.codigo.FORBIDDEN;
                Respuesta.estatus = MensajesEstados.ErrorAcceso;

                respuesta.Response = Respuesta;
                respuesta.Lessons  = null;
            }

            return(respuesta);
        }
Beispiel #3
0
        public String getListLessons()
        {
            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 ResponseStudentLessons(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 ResponseStudentLessons(Respuesta, null));
                    }
                    else
                    {
                        RequestStudentLessons Parametros = JsonConvert.DeserializeObject <RequestStudentLessons>(POST);
                        string Mensaje = "";
                        if (parametrosValidos(Parametros, ref Mensaje))
                        {
                            ADStudent          coursesAD = new ADStudent();
                            RespStudentLessons Respuesta = coursesAD.getListLessons(Parametros);
                            JSON = JsonConvert.SerializeObject(new ResponseStudentLessons(Respuesta.Response, Respuesta.Lessons));
                        }
                        else
                        {
                            RespStudent Respuesta = new RespStudent();
                            Respuesta.estatus = Mensaje;
                            Respuesta.code    = CodigosRespuesta.codigo.BAD_REQUEST;
                            JSON = JsonConvert.SerializeObject(new ResponseStudentLessons(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 ResponseStudentLessons(Respuesta, null));
            }
            return(JSON);
        }
Beispiel #4
0
        public RespStudentAnswers TakeLesson(RequestStudentAnswers Parametros)
        {
            RespStudentAnswers respuesta = new RespStudentAnswers();
            studentCore        core      = new studentCore();
            string             mensaje   = "";
            int idStudent = core.validateStudent(Parametros.RQ.user_number, Parametros.RQ.user_password, ref mensaje);

            if (idStudent != -1)
            {
                //get info lesson
                int              lessonPoints     = 0;
                Lesson           lesson           = new lessonsCore().getLesson(Parametros.RQ.ID_lesson, ref mensaje);
                List <Questions> questions_lesson = new questionsCore().getListQuestion(Parametros.RQ.ID_lesson, ref mensaje);
                List <Questions> questions_answer = Parametros.RQ.Questions;
                if (validateAnswers(questions_lesson, questions_answer, ref mensaje))
                {
                    if (lesson != null)
                    {
                        if (questions_lesson != null && questions_lesson.Count > 0)
                        {
                            foreach (Questions question in questions_lesson)
                            {
                                Questions answers = Parametros.RQ.Questions.Where(w => w.ID_question == question.ID_question).FirstOrDefault();
                                evaluateQuestion(question, answers, ref lessonPoints);
                            }
                        }
                    }

                    if (lessonPoints >= lesson.lesson_minPoints)
                    {
                        bool Correcto = core.TakeLesson(Parametros.RQ.ID_lesson, lessonPoints, idStudent, ref mensaje);
                        if (Correcto)
                        {
                            RespStudent Respuesta = new RespStudent();
                            Respuesta.code     = CodigosRespuesta.codigo.OK;
                            Respuesta.estatus  = mensaje;
                            respuesta.Response = Respuesta;
                        }
                        else
                        {
                            RespStudent Respuesta = new RespStudent();
                            Respuesta.code     = CodigosRespuesta.codigo.INTERNAL_SERVER_ERROR;
                            Respuesta.estatus  = mensaje;
                            respuesta.Response = Respuesta;
                        }
                    }
                    else
                    {
                        RespStudent Respuesta = new RespStudent();
                        Respuesta.code     = CodigosRespuesta.codigo.OK;
                        Respuesta.estatus  = "No cumple con el mínimo de puntos para pasar la lección.";
                        respuesta.Response = Respuesta;
                    }
                }
                else
                {
                    RespStudent Respuesta = new RespStudent();
                    Respuesta.code     = CodigosRespuesta.codigo.INTERNAL_SERVER_ERROR;
                    Respuesta.estatus  = mensaje;
                    respuesta.Response = Respuesta;
                }
            }
            else
            {
                RespStudent Respuesta = new RespStudent();
                Respuesta.code     = CodigosRespuesta.codigo.FORBIDDEN;
                Respuesta.estatus  = MensajesEstados.ErrorAcceso;
                respuesta.Response = Respuesta;
            }
            return(respuesta);
        }