private async void ClickrgButton(IUICommand command) { // Register the student if (SelectedStudent != null) { var st = new Registration(SelectedStudent.Id); await WsContext.CreateRegistration(st); MsgDialog = new MessageDialog("Du er hermed registreret"); WsContext.LoadStudentRegistrations(); SCommon.RegistrationList.Add(st); try { _timer = new DispatcherTimer(); _timer.Tick += StopAfterTime; _timer.Interval = new TimeSpan(0, 0, 0, 1, 500); _asyncOp = MsgDialog.ShowAsync(); _timer.Start(); } catch (TaskCanceledException) { //Caught } } }
public async Task CreateRegistration(Registration registration) { handler = new HttpClientHandler(); handler.UseDefaultCredentials = true; using (var client = new HttpClient(handler)) { client.BaseAddress = new Uri(ServerUrl); client.DefaultRequestHeaders.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); try { var response = await client.PostAsJsonAsync("Registrations", registration, CancelToken.Token); } catch (Exception ex) { new MessageDialog(ex.Message).ShowAsync(); } } }