protected override async void OnNavigatedTo(NavigationEventArgs e) { SystemTray.IsVisible = true; _centerId = NavigationContext.QueryString["CenterId"]; _centerName = NavigationContext.QueryString["CenterName"]; pivot.Title = _centerName; try { txtNoPacients.Visibility = Visibility.Collapsed; txtNoNeeds.Visibility = Visibility.Collapsed; _center = (await Service.GetTable<Center>() .Where(t => t.Id == _centerId).ToListAsync()).FirstOrDefault(); if (e.NavigationMode == NavigationMode.New) { var isAttending = (await Service.GetTable<DisasterAttend>() .Where(t => t.DisasterId == _center.DisasterId && t.ParticipantId == App.User.Id) .ToListAsync()).FirstOrDefault(); if (App.User.Type == UserType.Medic && isAttending != null) { var button = new ApplicationBarIconButton { IconUri = new Uri("/Assets/AppBar/add.png", UriKind.RelativeOrAbsolute), IsEnabled = true, Text = "add patient" }; button.Click += AddPatient_Click; ApplicationBar.Buttons.Add(button); } } var pin = new Pushpin() { Location = new GeoCoordinate(_center.Latitude, _center.Longitude), Content = _centerName, }; map.Children.Add(pin); map.Center = new GeoCoordinate(_center.Latitude, _center.Longitude); var patients = await Service.GetTable<Pacient>().Where(t => t.CenterId == _centerId).ToListAsync(); if (patients.Count == 0) txtNoPacients.Visibility = Visibility.Visible; else lstPacients.ItemsSource = patients; var needs = await Service.GetTable<Needs>().Where(t => t.CenterId == _centerId).ToListAsync(); if (needs.Count == 0) txtNoNeeds.Visibility = Visibility.Visible; else lstNeeds.ItemsSource = needs; } catch (Exception ex) { MessageBox.Show("Something went wrong!"); } }
private async void SaveButton_Click(object sender, EventArgs e) { DisableErrors(); if (!CheckInput()) return; var disaster = new Center { Name = txtName.Text, City = txtCity.Text, DisasterId = _disasterId, Latitude = map.Center.Latitude, Longitude = map.Center.Longitude, }; var error = false; try { await Service.InsertItemAsync(disaster); } catch (Exception ex) { error = true; } if (error) { MessageBox.Show("Something went wrong!"); return; } NavigationService.GoBack(); }