public async Task <List <Client> > GetClients() { HttpClient client = new HttpClient(); client.BaseAddress = new Uri(Properties.Settings.Default.ServerUrl); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Properties.Settings.Default.AuthCode); var result = await client.GetAsync("api/Clients?includeTriggers=true"); if (result.IsSuccessStatusCode) { ViewModelLocator.Instance.Main.AddSnacbkarSuccessMessageToQueeue("Loaded Clients"); return(Newtonsoft.Json.JsonConvert.DeserializeObject <List <Client> >(await result.Content.ReadAsStringAsync())); } else if (result.StatusCode == System.Net.HttpStatusCode.Unauthorized) { ViewModelLocator.Instance.Main.AddSnacbkarErrorMessageToQueeue("User not authorized. Please Login"); appManager.Logout(); return(new List <Client>()); } else { ViewModelLocator.Instance.Main.AddSnacbkarErrorMessageToQueeue("Failed to load clients. Please try again"); return(new List <Client>()); } }
private void Logout() { appManager.Logout(); Username = ""; }