public void TestSights()
        {
            // Read sights in JSON format from text file
            Uri uri = new Uri("sights.txt", UriKind.Relative);
            StreamResourceInfo streamResourceInfo = Application.GetResourceStream(uri);
            Stream stream = streamResourceInfo.Stream;
            StreamReader reader = new StreamReader(stream);

            // Parse JSON
            JArray jsonSights = JArray.Parse(reader.ReadToEnd());

            // Create sights
            Sights sights = new Sights(jsonSights, 40.115627, -88.220987);

            // Check that the sights were created correctly
            Assert.AreEqual(2, sights.Count);
            Assert.AreEqual("\"well\"", sights[0].Name);
            Assert.AreEqual("\"Das Cafe\"", sights[1].Name);

            // Check that the sights are sorted correctly
            ObservableCollection<Sight> sortedSights = Sights.GetSortedSights(sights);
            Assert.AreEqual(sights.Count, sortedSights.Count);
            Assert.AreEqual("\"Das Cafe\"", sortedSights[0].Name);
            Assert.AreEqual("\"well\"", sortedSights[1].Name);
        }
 public void ClearDatabase()
 {
     Tours.RemoveRange(Tours.ToList());
     Clients.RemoveRange(Clients.ToList());
     Excursions.RemoveRange(Excursions.ToList());
     ExcursionSights.RemoveRange(ExcursionSights.ToList());
     Sights.RemoveRange(Sights.ToList());
 }
Esempio n. 3
0
        public void EditSight(SightEditViewModel model)
        {
            Sights sight = unitOfWork.SightsRepository.GetAll()
                           .Include(c => c.Coordinates)
                           .FirstOrDefault(s => s.SightId == model.SightId)
                           ?? throw new ArgumentException("Забележителността не е намерена!");

            sight.Coordinates = AreCoordinatesValid(model.Latitude, model.Longitude)
                ? new Coordinates {
                Latitude = model.Latitude, Longtitude = model.Longitude
            }
                : null;

            unitOfWork.SightsRepository.Edit(sight);
            unitOfWork.Save();
        }
Esempio n. 4
0
        public void CreateSight(SightCreateViewModel model)
        {
            Sights sight = new Sights
            {
                SightName = model.SightName,
                SightInfo = model.SightInfo,
                CityId    = model.CityId
            };

            if (AreCoordinatesValid(model.Latitude, model.Longitude))
            {
                sight.Coordinates = new Coordinates
                {
                    Latitude   = model.Latitude,
                    Longtitude = model.Longitude
                };
            }

            unitOfWork.SightsRepository.Add(sight);
            unitOfWork.Save();
        }
 public ContentLoader_Optics(Sights sight, StackLayout layout)
 {
     this.sight  = sight;
     this.layout = layout;
 }
        /// <summary>
        /// Called when the HTTP message to the server requesting the list of
        /// sights was successful.
        /// </summary>
        /// <param name="responseStream">The HTTP response stream.</param>
        private void GettingSightsListSucceeded(Stream responseStream)
        {
            StreamReader reader = new StreamReader(responseStream);

            try
            {
                // Try to parse the HTTP response as a JSON object
                JArray jsonSights = JArray.Parse(reader.ReadToEnd());

                // Created a collection of sights sorted by the distance to the current location
                Sights sights = new Sights(jsonSights, App.CurrentLatitude, App.CurrentLongitude);
                ObservableCollection<Sight> sortedSights = Sights.GetSortedSights(sights);

                // If the HTTP response parsed as JSON, we got the list of sights.
                Deployment.Current.Dispatcher.BeginInvoke(
                    new Action(() =>
                    {
                        SightsList.ItemsSource = sortedSights;
                        NotificationTextBlock.Text = "";
                    }));
            }
            catch (JsonReaderException e)
            {
                // If the HTTP response did NOT parse as JSON, getting the list of sights failed.
                NotificationTextBlock.Dispatcher.BeginInvoke(
                    new Action(() =>
                    {
                        NotificationTextBlock.Text = "Retrieving Sights Failed: Unknown error.";
                    }));
            }
            finally
            {
                reader.Close();
            }
        }
        /// <summary>
        /// Called when the HTTP message to the server requesting the list of
        /// sights was successful.
        /// </summary>
        /// <param name="responseStream">The HTTP response stream.</param>
        private void GettingSightsListSucceeded(Stream responseStream)
        {
            StreamReader reader = new StreamReader(responseStream);

            try
            {
                // Try to parse the HTTP response as a JSON object
                JArray jsonSights = JArray.Parse(reader.ReadToEnd());

                // Created a collection of sights
                sights = new Sights(jsonSights, App.CurrentLatitude, App.CurrentLongitude);

                Deployment.Current.Dispatcher.BeginInvoke(
                    new Action(() =>
                    {
                        // For each sight, place a pin on the map.
                        foreach (Sight sight in sights)
                        {
                            var pin = new Pushpin();
                            pin.Location = new GeoCoordinate(sight.Latitude, sight.Longitude);
                            pin.Content = sight.Name;
                            sightsMap.Children.Add(pin);

                            // Add a handler for when pin is clicked, select that sight.
                            pin.AddHandler(Pushpin.MouseLeftButtonUpEvent, new MouseButtonEventHandler(PinClick), true);
                        }
                        NotificationTextBlock.Text = "";
                    })
                );

                // Show the map and buttons for map on the page.
                Deployment.Current.Dispatcher.BeginInvoke(
                   new Action(() =>
                   {
                       sightsMap.Visibility = Visibility.Visible;
                       ZoomInButton.Visibility = Visibility.Visible;
                       ZoomOutButton.Visibility = Visibility.Visible;
                       ChangeToRoadViewButton.Visibility = Visibility.Visible;
                       ChangeToAerialViewButton.Visibility = Visibility.Visible;

                   }));
            }
            catch (JsonReaderException e)
            {
                // If the HTTP response did NOT parse as JSON, getting the list of sights failed.
                NotificationTextBlock.Dispatcher.BeginInvoke(
                    new Action(() =>
                    {
                        NotificationTextBlock.Text = "Retrieving Sights Failed: Unknown error.";
                    }));
            }
            finally
            {
                reader.Close();

                //change so that current location is on center?
                NotificationTextBlock.Dispatcher.BeginInvoke(
                    new Action(() =>
                    {
                        sightsMap.Center = new GeoCoordinate(App.CurrentLatitude, App.CurrentLongitude);
                        sightsMap.ZoomLevel = 8;
                    })
                );

            }
        }
 private void detach_Sights1(Sights entity)
 {
     this.SendPropertyChanging();
     entity.Destination1 = null;
 }
 partial void DeleteSights(Sights instance);
 partial void UpdateSights(Sights instance);
 partial void InsertSights(Sights instance);