示例#1
0
        public List <LessonResponse> ViewLessons()
        {
            List <LessonResponse> lst     = new List <LessonResponse>();
            List <Lesson>         lessons = new List <Lesson>();

            UserResponse user  = new UserResponse();
            string       token = GetToken();

            if (userService.VerifyRol(token) != 2 && userService.VerifyRol(token) != 3)
            {
                return(null);
            }

            try
            {
                int user_id = userService.GetId(token);
                lessons = lessonService.FindByUser(user_id);
                int n = lessons.Count();

                for (int i = 0; i < n; i++)
                {
                    User            tr       = userService.FindById(lessons[i].teacher_id);
                    TeacherResponse teacher  = new TeacherResponse();
                    Country         country  = countryService.FindById(tr.country_id);
                    List <string>   language = new List <string>();
                    List <int>      wtt      = languageService.WantToTeach(tr.id);
                    int             m        = wtt.Count();

                    for (int j = 0; j < m; j++)
                    {
                        Language lng = new Language();
                        lng = languageService.FindById(wtt[j]);
                        language.Add(lng.name);
                    }

                    teacher.country     = country.name;
                    teacher.description = tr.description;
                    teacher.gender      = tr.gender;
                    teacher.id          = tr.id;
                    teacher.image       = tr.image;
                    teacher.languages   = language;
                    teacher.lastname    = tr.lastname;
                    teacher.mobilephone = tr.mobilephone;
                    teacher.name        = tr.name;

                    LessonResponse response = new LessonResponse();
                    Task           task     = new Task();
                    task                 = taskService.FindById(lessons[i].task_id);
                    response.day         = Convert.ToDateTime(lessons[i].day);
                    response.description = lessons[i].description;
                    response.id          = lessons[i].id;
                    response.latitude    = lessons[i].latitude;
                    response.lenght      = lessons[i].lenght;
                    response.status      = lessons[i].status;
                    response.student_id  = lessons[i].student_id;
                    response.task        = task.name;
                    response.teacher     = teacher;

                    lst.Add(response);
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message.ToString());
            }

            return(lst);
        }