Пример #1
0
        public async Task <bool> FetchTeacherData(string token)
        {
            var tokenField = "Token " + token;

            try
            {
                var httpClient = new HttpClient();
                System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
                System.Net.ServicePointManager.ServerCertificateValidationCallback +=
                    delegate(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate,
                             System.Security.Cryptography.X509Certificates.X509Chain chain,
                             System.Net.Security.SslPolicyErrors sslPolicyErrors)
                {
                    return(true);        // **** Always accept
                };

                httpClient.DefaultRequestHeaders.Add("Authorization", tokenField);
                var response = await httpClient.GetAsync("https://teenoh.webfactional.com/teacher/");

                if (response.IsSuccessStatusCode)
                {
                    HttpContent content = response.Content;
                    var         json    = await content.ReadAsStringAsync();

                    var teacherData = JsonConvert.DeserializeObject <TeacherData>(json);
                    App.TeacherData        = teacherData;
                    App.OngoingAttendances = new List <Models.OngoingAttendance>();
                    foreach (var course in teacherData.courses)
                    {
                        foreach (var attendance in course.attendances)
                        {
                            if (attendance.is_active == true)
                            {
                                var ongoingAttendance = new OngoingAttendance
                                {
                                    id               = attendance.id,
                                    course_name      = course.name,
                                    code             = course.code,
                                    credits          = course.credits,
                                    venue            = attendance.venue,
                                    name             = attendance.name,
                                    is_active        = attendance.is_active,
                                    present_students = attendance.present_students
                                };
                                App.OngoingAttendances.Add(ongoingAttendance);
                            }
                        }
                    }
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Пример #2
0
 public PresentStudentsViewModel(OngoingAttendance attendance)
 {
     RefreshCommand      = new Command(RefreshAction);
     token               = "Token" + ((App)Application.Current).token;
     OngoingAttendance   = attendance;
     StudentsList        = OngoingAttendance.present_students.ToList();
     AttendanceModelType = "OngoingAttendance";
 }
Пример #3
0
 public SingleOngoingAttendanceViewModel(INavigation _navigation, OngoingAttendance _attendance)
 {
     IsBusy                = false;
     IsError               = false;
     Navigation            = _navigation;
     Attendance            = _attendance;
     StopAttendanceCommand = new Command(StopAttendance);
     ViewPresentCommand    = new Command(ViewPresentStudents);
     RefreshCommand        = new Command(RefreshAction);
 }
        public OngoingAttendanceView(OngoingAttendance ongoingAttendance)
        {
            InitializeComponent();
            BindingContext = new SingleOngoingAttendanceViewModel(this.Navigation, ongoingAttendance);

            course_name.Text     = ongoingAttendance.course_name;
            code.Text            = ongoingAttendance.code;
            credits.Text         = ongoingAttendance.credits.ToString() + " credits";
            attendance_name.Text = "Attendance Tag: " + ongoingAttendance.name;
        }
Пример #5
0
 public PresentStudents(OngoingAttendance attendance)
 {
     InitializeComponent();
     BindingContext = new PresentStudentsViewModel(attendance);
 }