public BrightnessResponse SetBrightness(LoginResponse token, int value) { ConsoleOutput.WriteLine(string.Format("- Set Brightness to: {0}", value), ConsoleColor.Yellow); Dictionary <string, string> headers = new Dictionary <string, string>(); headers.Add("X-Auth-Token", token.Authentication_token); BrightnessCommand setMode = new BrightnessCommand("enabled", "A", value); string jsonString = JsonSerializer.Serialize(setMode, JsonOptions); var task = Task.Run(async() => await this.MakePOSTRequest(this.baseUrl + this.modeUrl, jsonString, headers)); task.Wait(); if (task.Result != null && task.Result.WasSuccessful) { BrightnessResponse response = JsonSerializer.Deserialize <BrightnessResponse>(task.Result.JsonResponse, JsonOptions); if (response != null) { response.Value = value; ConsoleOutput.WriteLine(string.Format(" Brightness Set: ({0})", response.Value), ConsoleColor.Cyan); return(response); } } else { ConsoleOutput.WriteLine(string.Format(" Set Brightness Failed ({0})", task.Result?.JsonResponse), ConsoleColor.Red); } return(null); }
public BrightnessResponse GetBrightness(LoginResponse token) { ConsoleOutput.WriteLine("- Fetching Brightness", ConsoleColor.Yellow); Dictionary <string, string> headers = new Dictionary <string, string>(); headers.Add("X-Auth-Token", token.Authentication_token); var task = Task.Run(async() => await this.MakeGETRequest(this.baseUrl + this.modeUrl, headers)); task.Wait(); if (task.Result != null && task.Result.WasSuccessful) { BrightnessResponse response = JsonSerializer.Deserialize <BrightnessResponse>(task.Result.JsonResponse, JsonOptions); if (response != null) { ConsoleOutput.WriteLine(string.Format(" Brightness Level: ({0})", response.Value), ConsoleColor.Cyan); return(response); } } else { ConsoleOutput.WriteLine(string.Format(" Get Brightness Failed ({0})", task.Result?.JsonResponse), ConsoleColor.Red); } return(null); }
public IActionResult Brightness() { var brightness = int.TryParse(TempData["Brightness"] as string, out var tempval) ? tempval : (int?)null; if (brightness != null) { var respondentAddress = new BrightnessResponse { Brightness = brightness.GetValueOrDefault() }; TempData.Keep(); return(View(respondentAddress)); } TempData.Keep(); return(View()); }
public IActionResult Brightness(BrightnessResponse data, string nextBtn) { if (nextBtn != null && ModelState.IsValid) { TempData["Brightness"] = data.Brightness.ToString(); TempData.Keep(); return(View("CheckAnswers", new RespondentAnswers { Name = TempData["FullName"] as string, EmailAddress = TempData["EmailAddress"] as string, Address = JsonConvert.DeserializeObject <RespondentAddress>(TempData["Address"] as string), Satisfied = TempData["Satisfied"] as string, Brightness = data.Brightness })); } TempData.Keep(); return(View()); }