private async void SetSession_ItemClick(object sender, RoutedEventArgs e) { var selectedInstruments = InstrumentsGrid.SelectedItems; var btn = (MenuItem)e.Source; int templateID = (int)btn.Tag; var templates = await _client.GetSessionTemplates().ConfigureAwait(true); if (!templates.WasSuccessful) { await this.ShowMessageAsync("Error", string.Join("\n", templates.Errors)).ConfigureAwait(true); return; } var template = templates.Result.FirstOrDefault(x => x.ID == templateID); if (template == null) { await this.ShowMessageAsync("Error", "Could not find template on the server").ConfigureAwait(true); return; } foreach (Instrument instrument in selectedInstruments) { instrument.SessionsSource = SessionsSource.Template; instrument.SessionTemplateID = templateID; if (instrument.Sessions == null) { instrument.Sessions = new List <InstrumentSession>(); } instrument.Sessions.Clear(); //Add the new sessions foreach (TemplateSession ts in template.Sessions) { instrument.Sessions.Add(ts.ToInstrumentSession()); } //update the instruments await _client.UpdateInstrument(instrument).ConfigureAwait(true); } }