示例#1
0
        protected override async Task OnInitializedAsync()
        {
            await GetWidth();

            // 40 is half the width of the spinner
            int leftPos = (Width / 2) - 40;

            leftPos = Math.Min(leftPos, 215);

            LeftPosStr = leftPos.ToString() + "px";

            StateHasChanged();

            Performances = (await TJBarnesService.GetHttpClient()
                            .GetFromJsonAsync <PerformanceJson[]>("api/performances")).ToList();
        }
示例#2
0
        protected async Task SaveDraft()
        {
            // Push the performance content to the API in JSON format

            // Generate nickname if none
            if (string.IsNullOrEmpty(Performance.Nickname))
            {
                StringBuilder sb    = new StringBuilder();
                int           items = 0;

                if (!string.IsNullOrEmpty(Performance.Location))
                {
                    sb.Append(Performance.Location);
                    items++;
                }

                if (items == 0)
                {
                    if (!string.IsNullOrEmpty(Performance.Platform))
                    {
                        sb.Append(Performance.Platform);
                        items++;
                    }
                }

                if (items > 0)
                {
                    sb.Append(" ");
                }

                sb.Append(Performance.Date.ToString("yyyy-MM-dd"));

                Performance.Nickname = sb.ToString();
            }

            PerformanceJson performanceJson = new PerformanceJson();

            // If Id = 0 then this is a new performance so Push an initial PerformanceJson object
            // to the API to get the new id
            if (Performance.Id == 0)
            {
                // Do an initial post of a blank PerformanceJson object to get the new Id
                HttpResponseMessage response = await TJBarnesService.GetHttpClient()
                                               .PostAsJsonAsync("api/performances", performanceJson);

                PerformanceJson returnValue = await response.Content.ReadFromJsonAsync <PerformanceJson>();

                // Update the Performance object with the new id
                Performance.Id = returnValue.Id;
            }

            // Now populate the performanceJson object
            performanceJson.Id       = Performance.Id;
            performanceJson.Nickname = Performance.Nickname;

            // Use the Serializer method of the JsonSerializer class (in the System.Text.Json namespace) to create
            // a Json object from the Performance object
            performanceJson.PerformanceContent = JsonSerializer.Serialize(Performance);

            await TJBarnesService.GetHttpClient()
            .PutAsJsonAsync($"api/performances/{Performance.Id}", performanceJson);
        }