public async Task <bool> Login(LoginRequest credentials) { var response = await _client.PostAsync($"{baseUrl}/api/Account/login", RequestHelper.GetStringContentFromObject(credentials)); if (response.StatusCode == HttpStatusCode.OK) { LoggedInUser = JsonConvert.DeserializeObject <LoginResult>(response.Content.ReadAsStringAsync().Result); _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", LoggedInUser.AccessToken); var value = 1; //https://localhost:44331/api/Users/ UserId = Convert.ToInt32(value); ReloadUI?.Invoke(); return(true); } return(false); }
private string ReceivedServerMessage(Server s, JObject message) { if (message["Action"].ToString() == "UpdateTest") { var sentTest = (Test)message["Test"].ToObject(typeof(Test)); this.currentTest.State = sentTest.State; switch (currentTest.State) { case Test.TestState.OnHold: this.TestState.State = UserState.OnHold; break; case Test.TestState.Started: this.TestState.State = UserState.Testing; break; } SendStateUpdate(); ReloadUI?.Invoke(); return(null); } if (message["Action"].ToString() == "AddTime") { var time = (TimeSpan)message["TimeSpan"]; this.TestState.RemainingTime += time; SendStateUpdate(); ReloadUI?.Invoke(); return(null); } if (message["Action"].ToString() == "Sync") { this.TestState = message["UserState"].ToObject <UserTestState>(); ReloadUI?.Invoke(); } if (message["Action"].ToString() == "Pause") { this.TestState.State = UserTestState.UserState.OnHold; ReloadUI?.Invoke(); } if (message["Action"].ToString() == "Resume") { this.TestState.State = UserTestState.UserState.Testing; ReloadUI?.Invoke(); } if (message["Action"].ToString() == "Handover") { try { this.Handover().Wait(); } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Handover Failed"); } } return(null); }