Exemplo n.º 1
0
        private void PinOnClicked(object sender, EventArgs e)
        {
            Pin clickedPin = sender as Pin;

            if (clickedPin != null)
            {
                Location clickedLocation = _viewModel.LocationItems.SingleOrDefault(l => l.Name == clickedPin.Label);
                LocationCollectionView.ScrollTo(clickedLocation, position: ScrollToPosition.Start);
            }
        }
Exemplo n.º 2
0
 private void LocationsMap_OnPinClicked(object sender, PinClickedEventArgs e)
 {
     if (e.Pin != null)
     {
         Location clickedLocation = _viewModel.LocationItems.SingleOrDefault(l => l.Name == (e.Pin).Label);
         if (clickedLocation != null)
         {
             LocationCollectionView.ScrollTo(clickedLocation, position: ScrollToPosition.Start);
         }
     }
 }
        private async void SaveLocationButton_OnClicked(object sender, EventArgs e)
        {
            Progeny progeny = ProgenyCollectionView.SelectedItem as Progeny;

            if (progeny == null)
            {
                return;
            }

            SaveLocationButton.IsEnabled   = false;
            CancelLocationButton.IsEnabled = false;
            _viewModel.IsBusy   = true;
            _viewModel.IsSaving = true;

            Location location = new Location();

            location.ProgenyId   = progeny.Id;
            location.AccessLevel = _viewModel.AccessLevel;
            string userEmail = await UserService.GetUserEmail();

            UserInfo userinfo = await UserService.GetUserInfo(userEmail);

            location.Author      = userinfo.UserId;
            location.Name        = NameEntry?.Text ?? "";
            location.StreetName  = StreetEntry?.Text ?? "";
            location.HouseNumber = HouseNumberEntry?.Text ?? "";
            location.District    = DistrictEntry?.Text ?? "";
            location.City        = CityEntry?.Text ?? "";
            location.PostalCode  = PostalCodeEntry?.Text ?? "";
            location.County      = CountyEntry?.Text ?? "";
            location.State       = StateEntry?.Text ?? "";
            location.Country     = CountryEntry?.Text ?? "";
            location.DateAdded   = DateTime.UtcNow;
            double lat;
            double lon;
            bool   latParsed = double.TryParse(LatitudeEntry.Text, out lat);
            bool   lonParsed = double.TryParse(LongitudeEntry.Text, out lon);

            if (latParsed)
            {
                location.Latitude = lat;
            }

            if (lonParsed)
            {
                location.Longitude = lon;
            }
            location.Notes = NotesEditor?.Text ?? "";
            location.Tags  = TagsEntry?.Text ?? "";

            DateTime locationTime = new DateTime(LocationDatePicker.Date.Year, LocationDatePicker.Date.Month, LocationDatePicker.Date.Day, LocationTimePicker.Time.Hours, LocationTimePicker.Time.Minutes, 0);

            location.Date = locationTime;
            Location newLocation = await ProgenyService.SaveLocation(location);

            _viewModel.IsBusy   = false;
            _viewModel.IsSaving = false;

            ErrorLabel.IsVisible = true;
            if (newLocation.LocationId == 0)
            {
                var ci = CrossMultilingual.Current.CurrentCultureInfo;
                ErrorLabel.Text              = resmgr.Value.GetString("ErrorLocationNotSaved", ci);
                ErrorLabel.BackgroundColor   = Color.Red;
                SaveLocationButton.IsEnabled = true;
                SaveLocationButton.IsEnabled = true;
            }
            else
            {
                var ci = CrossMultilingual.Current.CurrentCultureInfo;
                ErrorLabel.Text                      = resmgr.Value.GetString("LocationSaved", ci) + newLocation.LocationId;
                ErrorLabel.BackgroundColor           = Color.Green;
                SaveLocationButton.IsVisible         = false;
                CancelLocationButton.Text            = "Ok";
                CancelLocationButton.BackgroundColor = Color.FromHex("#4caf50");
                CancelLocationButton.IsEnabled       = true;
                await Shell.Current.Navigation.PopModalAsync();
            }
        }