/// <summary> /// Gets all StudyGroups from the servers REST Api. /// </summary> public async Task UpdateJobTypesFromServer() { DbJobType db = new DbJobType(); System.Diagnostics.Debug.WriteLine("JobTypesController - UpdateJobTypesFromServer: initiated"); DbStudent dbStudent = new DbStudent(); string accessToken = dbStudent.GetStudentAccessToken(); if (accessToken == null) { Authenticater.Authorized = false; return; } Uri url = new Uri(Adress); System.Diagnostics.Debug.WriteLine("JobTypesController - url " + url.ToString()); var client = new HttpClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", accessToken); try { var response = await client.GetAsync(url); if (response.StatusCode == HttpStatusCode.OK) { System.Diagnostics.Debug.WriteLine("GetJobTypesFromServer response " + response.StatusCode.ToString()); var newJobTypes = await response.Content.ReadAsAsync<IEnumerable<JobType>>(); db.DeleteAllJobTypes(); db.InsertJobTypes(newJobTypes); } if (response.StatusCode == HttpStatusCode.Unauthorized) { Authenticater.Authorized = false; } } catch (Exception e) { System.Diagnostics.Debug.WriteLine("JobTypesController - UpdateJobTypesFromServer: await client.GetAsync(\"url\") Failed"); System.Diagnostics.Debug.WriteLine("JobTypesController - UpdateJobTypesFromServer: Exception msg: " + e.Message); System.Diagnostics.Debug.WriteLine("JobTypesController - UpdateJobTypesFromServer: Stack Trace: \n" + e.StackTrace); System.Diagnostics.Debug.WriteLine("JobTypesController - UpdateJobTypesFromServer: End Of Stack Trace"); } }