Ejemplo n.º 1
0
        public virtual async Task <CourseScheduleModel> AgregarHorario(CourseScheduleModel dato)
        {
            await bd.Set <CourseScheduleModel>().AddAsync(dato);

            await bd.SaveChangesAsync();

            return(dato);
        }
Ejemplo n.º 2
0
        public virtual async Task <ObservableCollection <CourseModel> > getcourses()
        {
            SessionModel currentSession = (await ObtenerTablaSession())[0];
            JArray       response       = await ServicioAPI.testCallHeaderArray("http://replica.javerianacali.edu.co:8100/WSMobile/mobile/v2/asignaturas", currentSession.TokenSession);

            List <UserModel> currentUsers = await ObtenerTablaUsuario();

            for (int i = 0; i < currentUsers.Count; i++)
            {
                if (currentUsers[i].Codigouser == currentSession.UserSession)
                {
                    CurrentUser = currentUsers[i];
                    break;
                }
            }
            currentCourses = await ObtenerTablaCursos();

            bool flag;

            for (int i = 0; i < response.Count; i++) //second response[i]["crse_id"].ToString()
            {
                CourseExplore = new CourseModel(response[i]["nom"].ToString(), response[i]["crse_id"].ToString(), response[i]["horario"][0]["doc"].ToString(), response[i]["notp"].ToString(), response[i]["porci"].ToString(), response[i]["class_section"].ToString(), response[i]["peri"].ToString(), CurrentUser);
                flag          = false;
                for (int j = 0; j < currentCourses.Count; j++)
                {
                    if (response[i]["crse_id"].ToString() == currentCourses[j].CodCursoCourse && currentCourses[j].User.userModelID == CurrentUser.userModelID)
                    {
                        await ActualizarCurso(currentCourses[j]);

                        flag = true;
                        break;
                    }
                }
                if (!flag)
                {
                    await AgregarCurso(CourseExplore);

                    //CourseScheduleExplore = new CourseScheduleModel(response[i]["crse_id"].ToString(), response[i]["horario"][0]["doc"].ToString(), response[i]["horario"][0]["doc"].ToString(), response[i]["horario"][0]["dia"].ToString(), response[i]["horario"][0]["doc"].ToString(), CourseExplore);
                    //await AgregarHorario(CourseScheduleExplore);
                }
            }
            List <CourseScheduleModel> currentHorarios = await ObtenerTablaHorarios();

            for (int i = 0; i < CurrentUser.Cursos.Count; i++)
            {
                //CurrentUser.Cursos[i].NameCourse = "";
                promedioFLOAT += float.Parse(CurrentUser.Cursos[i].AverageGradeCourse);
                foreach (var hor in response[i]["horario"])
                {
                    //CurrentUser.Cursos[i].NameCourse = CurrentUser.Cursos[i].NameCourse+"##"+ CurrentUser.Cursos[i].CodCursoCourse;
                    flag = true;
                    for (int j = 0; j < currentHorarios.Count; j++)
                    {
                        if (currentHorarios[j].IdCourseSchedule == response[i]["crse_id"].ToString() && currentHorarios[j].Course.User.Codigouser == currentSession.UserSession)
                        {
                            flag = false;
                            //CurrentUser.Cursos[i].NameCourse = CurrentUser.Cursos[i].NameCourse+"$" + currentHorarios[j].IdCourseSchedule + "#a#" + response[i]["crse_id"].ToString() + CurrentUser.Cursos[i].User.Codigouser + "#b#" + currentSession.UserSession + "#f#" + flag.ToString();
                        }
                    }
                    //CurrentUser.Cursos[i].NameCourse = CurrentUser.Cursos[i].NameCourse + "$"+ currentHorarios[j].IdCourseSchedule + "#a#" +response[i]["crse_id"].ToString() + CurrentUser.Cursos[i].User.Codigouser + "#b#" + currentSession.UserSession + "#f#"+flag.ToString();
                    if (flag)
                    {
                        CourseScheduleExplore = new CourseScheduleModel(response[i]["crse_id"].ToString(), hor["hora"].ToString(), hor["hora"].ToString(), hor["dia"].ToString(), hor["saln"].ToString(), CurrentUser.Cursos[i]);
                        await AgregarHorario(CourseScheduleExplore);
                    }
                }
                //CourseScheduleExplore = new CourseScheduleModel(response[i]["crse_id"].ToString(), response[i]["horario"][0]["doc"].ToString(), response[i]["horario"][0]["doc"].ToString(), response[i]["horario"][0]["dia"].ToString(), response[i]["horario"][0]["doc"].ToString(), CurrentUser.Cursos[i]);
                //await AgregarHorario(CourseScheduleExplore);
                //CurrentUser.Cursos[i].NameCourse = CurrentUser.Cursos[i].NameCourse.Substring(0,10) + "#" + CurrentUser.Cursos[i].Horarios.Count.ToString();
                CurrentUser.Cursos[i].NameCourse = CurrentUser.Cursos[i].NameCourse.Substring(0, Math.Min(26, CurrentUser.Cursos[i].NameCourse.Length));
                cursos.Add(CurrentUser.Cursos[i]);

                //CourseScheduleExplore = new CourseScheduleModel(response[i]["crse_id"].ToString(), response[i]["horario"][0]["doc"].ToString(), response[i]["horario"][0]["doc"].ToString(), response[i]["horario"][0]["day"].ToString(), response[i]["horario"][0]["doc"].ToString());
                //CourseScheduleExplore = new CourseScheduleModel(response[i]["crse_id"].ToString(), response[i]["horario"][0]["doc"].ToString(), "a","as","a");
            }
            promedioFLOAT /= CurrentUser.Cursos.Count;
            promedio       = Convert.ToString(promedioFLOAT);
            promedio       = promedio.Substring(0, Math.Min(4, promedio.Length));
            return(cursos);
        }