async Task Load(int id) { // Get a test from the API AVTestData aVTestData = await TJBarnesService.GetHttpClient() .GetFromJsonAsync <AVTestData>("api/avtests/" + id.ToString()); // Use the Deserializer method of the JsonSerializer class (in the System.Text.Json namespace) to create // a BlowCore object BlowCore blowCore = JsonSerializer.Deserialize <BlowCore>(aVTestData.AVTestSpec); // Now create a Blow object from the BlowCore object blow = new Blow(); blow.LoadBlow(blowCore); blow.BellColor = Constants.UnstruckTestBellColor; testSpec.ShowGaps = false; StateHasChanged(); }
async Task Save() { testSpec.SpinnerSaving = true; testSpec.SaveLabel = "Wait"; testSpec.ControlsDisabled = true; screen.PlayDisabled = true; blow.BellColor = Constants.DisabledUnstruckTestBellColor; StateHasChanged(); // Push the created test to the API in JSON format // Start by creating a BlowCore object, which just has the inherited properties from Blow // Note implicit cast from child to parent BlowCore blowCore = blow; // Next use the Serializer method of the JsonSerializer class (in the System.Text.Json namespace) to create // a Json object from the BlowCore object AVTestData aVTestData = new AVTestData { AVTestSpec = JsonSerializer.Serialize(blowCore) }; // Push the Json object to the API await TJBarnesService.GetHttpClient().PostAsJsonAsync("api/avtests", aVTestData); // Refresh the contents of the Select Test dropdown aVTestsData = (await TJBarnesService.GetHttpClient() .GetFromJsonAsync <AVTestData[]>("api/avtests")).ToList(); testSpec.SpinnerSaving = false; testSpec.Saved = true; StateHasChanged(); await Task.Delay(1000); testSpec.Saved = false; testSpec.SaveLabel = "Save"; testSpec.ControlsDisabled = false; screen.PlayDisabled = false; blow.BellColor = Constants.UnstruckTestBellColor; StateHasChanged(); }