Exemplo n.º 1
0
        private void OnAddGeocacheClick(object sender, RoutedEventArgs args)
        {
            var dialog = new GeocacheDialog();

            dialog.Owner = this;
            dialog.ShowDialog();
            if (dialog.DialogResult == false)
            {
                return;
            }

            string contents = dialog.GeocacheContents;
            string message  = dialog.GeocacheMessage;
            // Add geocache to map and database here.
            var pin = AddPin(latestClickLocation, "Person", Colors.Gray);

            pin.MouseDown += (s, a) =>
            {
                // Handle click on geocache pin here.
                MessageBox.Show("You clicked a geocache");
                UpdateMap();

                // Prevent click from being triggered on map.
                a.Handled = true;
            };
        }
        private void OnAddGeocacheClick(object sender, RoutedEventArgs args)
        {
            if (activePerson == null)
            {
                MessageBox.Show("Please select a person before adding a geocache.");
            }
            else
            {
                var dialog = new GeocacheDialog();
                dialog.Owner = this;
                dialog.ShowDialog();
                if (dialog.DialogResult == false)
                {
                    return;
                }

                string contents = dialog.GeocacheContents;
                string message  = dialog.GeocacheMessage;

                // Add geocache to map and database here.
                Geocache geocache = AddGeocacheToDatabase(dialog, latestClickLocation);
                var      pin      = AddPin(latestClickLocation, HooverOnGeocachePinShowToolTip(geocache), Colors.Black, geocache);

                pin.MouseDown += (s, a) =>
                {
                    // Handle click on geocache pin here.
                    var clickedGeocache = db.Geocache.First(p => p.ID == geocache.ID);
                    ClickedGeochachePin(clickedGeocache);

                    // Prevent click from being triggered on map.
                    a.Handled = true;
                };
            }
        }
Exemplo n.º 3
0
        // Here the geocache object and pin is created and saved to database on map right-click.
        private async void BeginOnAddGeocacheClick(object sender, RoutedEventArgs args)
        {
            using (var database = new AppDbContext())
            {
                if (ActivePersonID == 0)
                {
                    MessageBox.Show("Please select/add a person before adding a geocache.");
                }
                else
                {
                    var dialog = new GeocacheDialog();
                    dialog.Owner = this;
                    dialog.ShowDialog();
                    if (dialog.DialogResult == false)
                    {
                        return;
                    }
                    string contents = dialog.GeocacheContents;
                    string message  = dialog.GeocacheMessage;

                    geocache.Coordinates  = coordinates;
                    geocache.Content      = contents;
                    geocache.Message      = message;
                    coordinates.Longitude = latestClickLocation.Longitude;
                    coordinates.Latitude  = latestClickLocation.Latitude;

                    var persons = database.Person.Include(p => p.Geocaches).Where(p => p.ID == ActivePersonID).ToArray();

                    foreach (var p in persons)
                    {
                        string geocacheToolTip = "long: " + coordinates.Longitude + "\nlat:    " + coordinates.Latitude + "\nContent: " + contents
                                                 + "\nMessage: " + message + "\nPlaced by: " + p.FirstName + " " + p.LastName;
                        var pin = AddPin(latestClickLocation, geocacheToolTip, Colors.Black);
                    }

                    geocache.Person.ID = ActivePersonID;
                    geocache.ID        = 0;

                    var task = Task.Run(() =>
                    {
                        database.Add(geocache);
                        database.SaveChanges();
                    });
                    await(task);
                }
            }
        }
Exemplo n.º 4
0
        private async void OnAddGeocacheClickAsync(object sender, RoutedEventArgs args)
        {
            if (activePinPerson == null)
            {
                MessageBox.Show("Select Person First", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            var dialog = new GeocacheDialog
            {
                Owner = this
            };

            dialog.ShowDialog();
            if (dialog.DialogResult == false)
            {
                return;
            }

            string contents = dialog.GeocacheContents;
            string message  = dialog.GeocacheMessage;

            string tooltip = $"Latitude:\t\t{latestClickLocation.Latitude}\r\nLongitude:\t{latestClickLocation.Longitude}\r\n" +
                             $"Made by:\t{activePinPerson.FirstName + " " + activePinPerson.LastName}\r\n" +
                             $"Contents:\t{contents}\r\nMessage:\t{message}";


            // Add geocache to map and database here.
            Pushpin pin = AddPin(latestClickLocation, tooltip, Colors.Black);

            pin.MouseLeftButtonDown += OnCachePinClick;

            var geocache = new Geocache()
            {
                Contents    = contents,
                Coordinates = latestClickLocation,
                Message     = message
            };

            await _db.AddGeocacheAsync(geocache, activePinPerson.ID);

            pin.Tag = new Dictionary <string, ITag> {
                ["Person"] = activePinPerson, ["Geocache"] = geocache
            };
            cachePins.Add(pin);
        }
        private Geocache AddGeocacheToDatabase(GeocacheDialog dialog, Location latestClickLocation)
        {
            Geocache geocache = new Geocache()
            {
                PersonID      = activePerson.ID,
                GeoCoordinate = new Coordinate()
                {
                    Latitude  = latestClickLocation.Latitude,
                    Longitude = latestClickLocation.Longitude
                },
                Contents = dialog.GeocacheContents,
                Message  = dialog.GeocacheMessage
            };

            db.Add(geocache);
            db.SaveChanges();

            return(geocache);
        }
        private void OnAddGeocacheClick(object sender, RoutedEventArgs args)
        {
            if (CurrentPerID != 0)
            {
                var dialog = new GeocacheDialog();
                dialog.Owner = this;
                dialog.ShowDialog();
                if (dialog.DialogResult == false)
                {
                    return;
                }

                double latitude  = latestClickLocation.Latitude;
                double longitude = latestClickLocation.Longitude;
                string contents  = dialog.GeocacheContents;
                string message   = dialog.GeocacheMessage;


                Geocache geocache = new Geocache
                {
                    Latitude  = latitude,
                    Longitude = longitude,
                    Contents  = contents,
                    Message   = message,
                    Person    = currentPerson
                };

                db.Add(geocache);
                db.SaveChanges();

                // Add geocache to map and database here.
                string messageGeo = TooltipMessageGeo(geocache);
                var    pinPerson  = AddGeoPin(latestClickLocation, messageGeo, Colors.Gray, 1, geocache);

                UpdateMap();
            }
            else
            {
                MessageBox.Show("You need to select a person");
            }
        }
        private void OnAddGeocacheClick(object sender, RoutedEventArgs args)
        {
            var dialog = new GeocacheDialog();

            dialog.Owner = this;
            dialog.ShowDialog();
            if (dialog.DialogResult == false)
            {
                return;
            }

            if (activePerson.FirstName != null)
            {
                string contents = dialog.GeocacheContents;
                string message  = dialog.GeocacheMessage;
                // Add geocache to map and database here.
                int cacheID = 1;
                foreach (var cache in geocaches)
                {
                    cacheID = cacheID + 1;
                }
                var geocache = new Geocache();
                geocache.ID        = cacheID;
                geocache.Latitude  = latestClickLocation.Latitude;
                geocache.Longitude = latestClickLocation.Longitude;
                geocache.Contents  = contents;
                geocache.Message   = message;
                geocache.Person    = db.Person.First(p => p.ID == activePerson.ID);


                db.Add(geocache);
                db.SaveChanges();
                OnMapLeftClick();
            }
            else
            {
                MessageBox.Show("Please select a person before adding a geocache.");
            }
        }