Exemplo n.º 1
0
        public LessonResponse ViewLesson(int id)
        {
            LessonResponse  response = new LessonResponse();
            TeacherResponse tr       = new TeacherResponse();
            User            teacher  = new User();
            string          token    = GetToken();

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

            try
            {
                Lesson lesson = lessonService.FindById(id);
                teacher = userService.FindById(lesson.teacher_id);
                Task task = taskService.FindById(lesson.task_id);

                Country country = countryService.FindById(teacher.country_id);

                List <string> language = new List <string>();
                List <int>    wtt      = languageService.WantToTeach(id);
                int           n        = wtt.Count();

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


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


                response.day         = Convert.ToDateTime(lesson.day);
                response.description = lesson.description;
                response.id          = lesson.id;
                response.latitude    = lesson.latitude;
                response.lenght      = lesson.lenght;
                response.status      = lesson.status;
                response.student_id  = lesson.student_id;
                response.task        = task.name;
                response.teacher     = tr;
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message.ToString());
            }

            return(response);
        }
Exemplo n.º 2
0
        public async Task <ResponseMessage> GetTeacherByIdAsync(string json)
        {
            using (IDbConnection _cn = new SqlConnection(Global.ConnectionString))
            {
                ResponseMessage rm = new ResponseMessage()
                {
                    Code = 0, Message = ""
                };
                if (_cn.State == ConnectionState.Closed)
                {
                    _cn.Open();
                }
                var dc = new DynamicParameters();
                dc.Add("@JSON", json);
                IDataReader rdr = await _cn.ExecuteReaderAsync("SP_CRUD_TEACHER", dc, commandType : CommandType.StoredProcedure);

                while (rdr.Read())
                {
                    TeacherResponse _teacher = new TeacherResponse
                    {
                        Id         = Convert.ToInt32(rdr["Id"]),
                        Name       = rdr["Name"].ToString(),
                        Gender     = rdr["Gender"].ToString(),
                        Salary     = Convert.ToDecimal(rdr["Salary"]),
                        InsertedOn = rdr["InsertedOn"].ToString()
                    };
                    rm.Code    = 1;
                    rm.Message = JsonConvert.SerializeObject(_teacher);
                }
                ;
                _cn.Close();
                return(rm);
            }
        }
Exemplo n.º 3
0
        public List <TeacherResponse> WantToLearn()
        {
            string                 token = GetToken();
            List <int>             users;
            List <User>            lnuser    = new List <User>();
            List <TeacherResponse> Uresponse = new List <TeacherResponse>();

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

            try
            {
                int user_id = userService.GetId(token);
                users = userService.WantToTeach(user_id);
                int n = users.Count();
                for (int i = 0; i < n; i++)
                {
                    User            user = userService.FindById(users[i]);
                    TeacherResponse tr   = new TeacherResponse();

                    Country country = new Country();
                    country = countryService.FindById(user.country_id);

                    List <string> language = new List <string>();
                    List <int>    wtt      = languageService.WantToTeach(users[i]);
                    int           m        = wtt.Count();

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

                    tr.country     = country.name;
                    tr.description = user.description;
                    tr.gender      = user.gender;
                    tr.id          = user.id;
                    tr.lastname    = user.lastname;
                    tr.mobilephone = user.mobilephone;
                    tr.name        = user.name;
                    tr.image       = user.image;
                    tr.languages   = language;
                    //aumentar lista con los lenguajes con user_id = users.id && wish_id == 1

                    Uresponse.Add(tr);
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message.ToString());
            }

            return(Uresponse);
        }
Exemplo n.º 4
0
        public object GetTeachers()
        {
            var teachers = _teacher.Select(s => s.Email).ToList();

            TeacherResponse commonTeachers = new TeacherResponse
            {
                teachers = teachers.ToArray()
            };

            return(commonTeachers);
        }
Exemplo n.º 5
0
        public async Task <TeacherResponse> GetAllTeachers()
        {
            var response = new TeacherResponse();

            try
            {
                var items = await _repository.GetAllTeachers();

                response = items.ToTeacherResponse();
            }
            catch (Exception e)
            {
                _logger.LogError(e, "LessonApplication Error");
                response.ResponseType = ResponseTypeEnum.Error;
            }
            return(response);
        }
Exemplo n.º 6
0
        public TeacherResponse Teacher(int id)
        {
            TeacherResponse tresponse = new TeacherResponse();
            string          token     = GetToken();

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

            try
            {
                User    teacher = userService.FindById(id);
                Country country = new Country();
                country = countryService.FindById(teacher.country_id);

                List <string> language = new List <string>();
                List <int>    wtt      = languageService.WantToTeach(id);
                int           n        = wtt.Count();

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

                tresponse.id          = teacher.id;
                tresponse.name        = teacher.name;
                tresponse.lastname    = teacher.lastname;
                tresponse.mobilephone = teacher.mobilephone;
                tresponse.description = teacher.description;
                tresponse.gender      = teacher.gender;
                tresponse.country     = country.name;
                tresponse.image       = teacher.image;
                tresponse.languages   = language;
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message.ToString());
            }

            return(tresponse);
        }
Exemplo n.º 7
0
        public TeacherResponse Map(Teacher teacher)
        {
            if (teacher == null)
            {
                return(null);
            }

            var teacherResponse = new TeacherResponse
            {
                Id              = teacher.Id,
                Firstname       = teacher.Firstname,
                Lastname        = teacher.Lastname,
                TeachesCourses  = teacher.Course.Select(HelperMapper.BasicMap),
                TeachesInSchool = HelperMapper.BasicMap(teacher.School),
                TeachesClasses  = teacher.Class.Select(HelperMapper.BasicMap)
            };

            return(teacherResponse);
        }
Exemplo n.º 8
0
        public static TeacherResponse ToTeacherResponse(this List <TeacherValue> teachers)
        {
            var response = new TeacherResponse();

            if (teachers.Count == 0)
            {
                return(response);
            }

            var items = teachers.Select(l => new TeacherItemResponse
            {
                TeacherId   = l.TeacherId,
                TeacherName = l.TeacherName,
            }
                                        );

            response.Items = new List <TeacherItemResponse>(items);
            return(response);
        }
Exemplo n.º 9
0
        public TeacherResponse getTeacher(int id)
        {
            var teacher = _context.Teachers.FirstOrDefault(x => x.id == id);

            if (teacher != null)
            {
                var teacherResponse = new TeacherResponse()
                {
                    id        = teacher.id,
                    surname   = teacher.surname,
                    name      = teacher.name,
                    title     = teacher.title,
                    userGroup = teacher.userGroup
                };

                return(teacherResponse);
            }

            return(null);
        }
Exemplo n.º 10
0
        public ActionResult <TeacherResponse> Get(Guid id)
        {
            try
            {
                var teacher = teacherRepository.Get(id);
                if (teacher != null)
                {
                    var classSchedules = classScheduleRepository
                                         .GetAll()
                                         .Where(cs => cs.Teacher.Id == id);

                    //TODO: This should be automapped
                    var result = new TeacherResponse
                    {
                        Id             = teacher.Id,
                        FirstName      = teacher.FirstName,
                        MiddleName     = teacher.MiddleName,
                        LastName       = teacher.LastName,
                        BirthDate      = teacher.BirthDate,
                        Gender         = teacher.Gender.Id,
                        Title          = teacher.Title.Id,
                        ClassSchedules = teacher.ClassSchedules.Select(cs => new ClassScheduleResponse
                        {
                            Id       = cs.Id,
                            Location = cs.Location
                        })
                    };
                    return(Ok(result));
                }

                return(NotFound());
            }
            catch (Exception e)
            {
                return(GenericServerErrorResult(e));
            }
        }
Exemplo n.º 11
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);
        }