示例#1
0
        protected void LoadDraft(int id)
        {
            PerformanceJson performanceJson = Performances.Where(p => p.Id == id).FirstOrDefault();

            // Use the Deserializer method of the JsonSerializer class (in the System.Text.Json namespace) to create
            // a Performance object
            Performance performance = JsonSerializer.Deserialize <Performance>(performanceJson.PerformanceContent);

            // Populate Performance service fields
            Performance.Id                  = performance.Id;
            Performance.Nickname            = performance.Nickname;
            Performance.Style               = performance.Style;
            Performance.StyleOther          = performance.StyleOther;
            Performance.AssociationDropDown = performance.AssociationDropDown;
            Performance.AssociationFreeForm = performance.AssociationFreeForm;
            Performance.Date                = performance.Date;
            Performance.Distributed         = performance.Distributed;
            Performance.Location            = performance.Location;
            Performance.County              = performance.County;
            Performance.Address             = performance.Address;
            Performance.Tenor               = performance.Tenor;
            Performance.Platform            = performance.Platform;
            Performance.Time                = performance.Time;
            Performance.ImportFromCompLib   = performance.ImportFromCompLib;
            Performance.CompLibId           = performance.CompLibId;
            Performance.Length              = performance.Length;
            Performance.Title               = performance.Title;
            Performance.Composer            = performance.Composer;
            Performance.Detail              = performance.Detail;

            Performance.NumRingers           = performance.NumRingers;
            Performance.BellsPerRinger       = performance.BellsPerRinger;
            Performance.AdditionalRingerInfo = performance.AdditionalRingerInfo;

            Performance.Ringers.Clear();

            foreach (RingerData ringerData in performance.Ringers)
            {
                Performance.Ringers.Add(ringerData);
            }

            Performance.NewMethodsNamed = performance.NewMethodsNamed;

            Performance.NewMethods.Clear();

            foreach (NewMethodData newMethodData in performance.NewMethods)
            {
                Performance.NewMethods.Add(newMethodData);
            }

            Performance.Footnotes      = performance.Footnotes;
            Performance.NormDepartures = performance.NormDepartures;

            NavManager.NavigateTo("/preview");
        }
示例#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);
        }