private async void Control2_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args)
        {
            var select = (args.SelectedItem as PlaceAutoComplete.Prediction);

            if (select == null)
            {
                return;
            }
            var res = await GeocodeHelper.GetInfo(select.place_id);

            SearchBox.Text = "";
            if (res == null || res.results.Length == 0)
            {
                await new MessageDialog("We couldn't find place location!").ShowAsync();
                return;
            }
            var ploc = res.results.FirstOrDefault().geometry.location;

            MapView.MapControl.Center = new Geopoint(
                new BasicGeoposition()
            {
                Latitude  = ploc.lat,
                Longitude = ploc.lng
            });
            MapView.StaticMapView.SearchResultPoint = new Geopoint(
                new BasicGeoposition()
            {
                Latitude  = ploc.lat,
                Longitude = ploc.lng
            });
            (DataContext as ViewModel).SearchResults.Clear();
            //SearchReq.Invoke(args.SelectedItem as ClassProduct.Product, null);
            //SearchBox.Visibility = Visibility.Collapsed;
            //BTNExpand.Visibility = Visibility.Visible;
        }
Beispiel #2
0
        private async void search_QuerySubmitted(object s, AutoSuggestBoxQuerySubmittedEventArgs args)
        {
            string         query  = null;
            AutoSuggestBox sender = (AutoSuggestBox)s;

            if (args.ChosenSuggestion == null)
            {
                query       = (await GeocodeHelper.SuggestAsync(args.QueryText))?.FirstOrDefault();
                sender.Text = query;
            }
            else
            {
                query = args.ChosenSuggestion as string;
            }
            if (query != null)
            {
                if (sender == searchFrom)
                {
                    VM.GeocodeFromLocation(query);
                }
                else
                {
                    VM.GeocodeToLocation(query);
                }
            }
        }
Beispiel #3
0
        void get_geocode_info()
        {
            context["geocode"] = () =>
            {
                var testCoordinates = new DecimalCoordinatePairModel
                {
                    Latitude  = 40.714224m,
                    Longitude = -73.961452m,
                };

                itAsync["can save to cache"] = async() =>
                {
                    var expected = @"Williamsburg Brooklyn New York";
                    var testRoot = "./";
                    var helper   = new CacheHelper(testRoot);
                    await helper.ClearCache();

                    await helper.SaveToCache(testCoordinates, expected);

                    var actual = await helper.ReadFromCache(testCoordinates);

                    actual.Should().Be(expected);
                };

                itAsync["can reverse geocode"] = async() =>
                {
                    var expected = @"Williamsburg Brooklyn New York";
                    var helper   = new GeocodeHelper();
                    var actual   = await helper.ReverseGeocode(testCoordinates);

                    actual.Should().Be(expected);
                };
            };
        }
Beispiel #4
0
        private async void ToTextField_EditingChanged(object sender, EventArgs e)
        {
            try
            {
                var searchText = _toTextField.Text;
                if (!string.IsNullOrEmpty(searchText))
                {
                    var suggestions = await GeocodeHelper.SuggestAsync(searchText);

                    var suggestionTableSource = new TableSource <string>(suggestions, (s) => s);
                    suggestionTableSource.TableRowSelected += ToSuggestionTableSource_TableRowSelected;
                    _toAutoCompleteTableView.Source         = suggestionTableSource;
                    _toAutoCompleteTableView.ReloadData();
                    var oldFrame = _toAutoCompleteTableView.Frame;
                    _toAutoCompleteTableView.Frame  = new CGRect(oldFrame.Left, oldFrame.Top, oldFrame.Width, suggestions.Count() * 30f);
                    _toAutoCompleteTableView.Hidden = false;
                }
                else
                {
                    _toAutoCompleteTableView.Hidden = true;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"{ex.Message}\n{ex.StackTrace}");
            }
        }
        private async void ListView_ItemClick(object sender, ItemClickEventArgs e)
        {
            var select = e.ClickedItem as PlaceAutoComplete.Prediction;

            if (select == null)
            {
                return;
            }
            var res = await GeocodeHelper.GetInfo(select.place_id);

            if (res == null)
            {
                return;
            }
            var ploc = res.results.FirstOrDefault().geometry.location;

            MapView.MapControl.Center = new Geopoint(
                new BasicGeoposition()
            {
                Latitude  = ploc.lat,
                Longitude = ploc.lng
            });
            MapView.StaticMapView.SearchResultPoint = new Geopoint(
                new BasicGeoposition()
            {
                Latitude  = ploc.lat,
                Longitude = ploc.lng
            });
            MapView.StaticSearchGrid.PopUP = false;
        }
        private async void Control2_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args)
        {
            var select = (args.SelectedItem as PlaceAutoComplete.Prediction);

            if (select == null)
            {
                return;
            }
            var res = await GeocodeHelper.GetInfo(select.place_id);

            if (res == null)
            {
                return;
            }
            SearchBox.Text = "";
            var ploc = res.results.FirstOrDefault().geometry.location;

            MapView.MapControl.Center = new Geopoint(
                new BasicGeoposition()
            {
                Latitude  = ploc.lat,
                Longitude = ploc.lng
            });
            //SearchReq.Invoke(args.SelectedItem as ClassProduct.Product, null);
            SearchBox.Visibility = Visibility.Collapsed;
            BTNExpand.Visibility = Visibility.Visible;
        }
Beispiel #7
0
        private void UpdateDisambiguationList()
        {
            lbxNames.Items.Clear();
            UInt32 geocode = 0;

            if (cbxProvinces.SelectedItem != null)
            {
                geocode = (cbxProvinces.SelectedItem as Entity).geocode;
            }
            if (cbxEntityType.SelectedItem != null)
            {
                var selectedType    = (EntityType)cbxEntityType.SelectedItem;
                var currentEntities = allEntities.Where(x => x.type == selectedType).ToList();
                var names           = currentEntities.GroupBy(x => x.name).Where(y => y.Count() > 1).OrderByDescending(z => z.Count()).ThenBy(z => z.First().english);
                var currentNames    = names.Select(x => new EntityList(x.OrderBy(y => y.geocode)));
                if (geocode != 0)
                {
                    currentNames = currentNames.Where(x => x.Entities.Any(y => GeocodeHelper.IsBaseGeocode(geocode, y.geocode)));
                }
                foreach (var x in currentNames)
                {
                    lbxNames.Items.Add(x);
                }
            }
        }
        public async Task GeocodeM3NW040()
        {
            await ProvisioningTests.EnsureData();

            var result = await GeocodeHelper.GeocodeAsync("M3NW040");

            Assert.IsNotNull(result);
        }
        public async Task SuggestM3NW040_SingleResult()
        {
            await ProvisioningTests.EnsureData();

            var result = await GeocodeHelper.SuggestAsync("M3NW040");

            Assert.AreEqual(1, result.Count());
            Assert.AreEqual("M3nw040", result.First());
        }
        public async Task SuggestM3NW0_MultipleResults()
        {
            await ProvisioningTests.EnsureData();

            var result = await GeocodeHelper.SuggestAsync("M3NW0");

            Assert.AreEqual(8, result.Count());
            Assert.IsTrue(result.All(r => r.StartsWith("M3nw0")));
        }
Beispiel #11
0
 private async void DraggablePin_Tapped(object sender, TappedRoutedEventArgs e)
 {
     await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async delegate
     {
         if (ClassInitializer.GetType() == typeof(DirectionsMainUserControl))
         {
             var Pointer = (await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/InAppIcons/GMP.png")));
             if (DirectionsMainUserControl.Origin == null)
             {
                 DirectionsMainUserControl.Origin = _map.Center;
                 _map.MapElements.Add(new MapIcon()
                 {
                     Location = _map.Center,
                     NormalizedAnchorPoint = new Point(0.5, 1.0),
                     Title = "Origin",
                     Image = RandomAccessStreamReference.CreateFromFile(Pointer),
                 });
                 DirectionsMainUserControl.OriginAddress = await GeocodeHelper.GetAddress(_map.Center);
             }
             else if (DirectionsMainUserControl.Destination == null)
             {
                 DirectionsMainUserControl.Destination = _map.Center;
                 _map.MapElements.Add(new MapIcon()
                 {
                     Location = _map.Center,
                     NormalizedAnchorPoint = new Point(0.5, 1.0),
                     Title = "Destination",
                     Image = RandomAccessStreamReference.CreateFromFile(Pointer)
                 });
                 DirectionsMainUserControl.DestinationAddress = await GeocodeHelper.GetAddress(_map.Center);
             }
         }
         if (ClassInitializer.GetType() == typeof(SavedPlacesUserControl))
         {
             if (SavedPlacesUserControl.PName == string.Empty)
             {
                 await new MessageDialog("Specify a name for this place").ShowAsync();
             }
             else
             {
                 try
                 {
                     SavedPlacesVM.AddNewPlace(new SavedPlacesVM.SavedPlaceClass()
                     {
                         Latitude  = _map.Center.Position.Latitude,
                         Longitude = _map.Center.Position.Longitude,
                         PlaceName = SavedPlacesUserControl.PName
                     });
                 }
                 catch (Exception ex)
                 {
                     await new MessageDialog(ex.Message).ShowAsync();
                 }
             }
         }
     });
 }
Beispiel #12
0
        /// <summary>
        /// This method allows the user to convert an address to a latitude and longitude pair.
        /// </summary>
        /// <param name="address">A string representing an address.</param>
        /// <returns>Double precision numbers representing latitude and longitude separated by a comma.</returns>
        public string getGeocode(string address)
        {
            // Create a LatLong object by passing in an address to our Geocode method from our GeocodeHelper private class
            LatLong result = GeocodeHelper.Geocode(address);

            // Format our pair of coordinates so that it is easy for anyone to parse
            string s = string.Format("{0},{1}", result.latitude, result.longitude);

            // Return our coordinates string
            return(s);
        }
Beispiel #13
0
        /// <summary>
        /// This method allows the user to convert coordinates to an address location.
        /// </summary>
        /// <param name="latitude">The latitude part of a coordinate pair, represented by a double precision number.</param>
        /// <param name="longitude">The longitude part of a coordinate pair, represented by a double precision number.</param>
        /// <returns>A string representing an address.</returns>
        public string getAddress(double latitude, double longitude)
        {
            // Create an Address object by passing in coordinates to our inverseGeocode method from our GeocodeHelper private class
            Address result = GeocodeHelper.inverseGeocode(latitude, longitude);

            // Fromat our resulting address string with each part separated by a comma.
            string s = string.Format("{0}, {1}, {2}, {3}", result.addressLine, result.locatlity, result.state, result.postal);

            // Return our address string
            return(s);
        }
        private async void Search_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(e.NewTextValue))
            {
                (sender as AutoCompleteView).Suggestions = null;
            }
            else
            {
                var suggestions = await GeocodeHelper.SuggestAsync(e.NewTextValue);

                (sender as AutoCompleteView).Suggestions = suggestions.ToList();
            }
        }
Beispiel #15
0
 // private
 private void ResolvePictureAddress(CapturedPictureViewModel picture)
 {
     if (GpsHelper.Instance.Watcher.Status == GeoPositionStatus.Ready)
     {
         picture.Position = GpsHelper.Instance.Watcher.Position.Location;
         GeocodeHelper.ReverseGeocodeAddress(
             Dispatcher,
             _credentialsProvider,
             picture.Position,
             result => picture.Address = result.Address.FormattedAddress);
     }
     else
     {
         picture.Position = GeoCoordinate.Unknown;
     }
 }
Beispiel #16
0
        private async void search_SuggestionsRequested(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
        {
            if (args.Reason == AutoSuggestionBoxTextChangeReason.UserInput)
            {
                if (string.IsNullOrWhiteSpace(sender.Text))
                {
                    sender.ItemsSource = null;
                }
                else
                {
                    var suggestions = await GeocodeHelper.SuggestAsync(sender.Text);

                    sender.ItemsSource = suggestions.ToList();
                }
            }
        }
Beispiel #17
0
        private async void FromTextField_EditingChanged(object sender, EventArgs e)
        {
            var searchText = _fromTextField.Text;

            if (!string.IsNullOrEmpty(searchText))
            {
                var suggestions = await GeocodeHelper.SuggestAsync(searchText);

                var suggestionTableSource = new TableSource <string>(suggestions, (s) => s);
                suggestionTableSource.TableRowSelected += FromSuggestionTableSource_TableRowSelected;
                _fromAutoCompleteTableView.Source       = suggestionTableSource;
                _fromAutoCompleteTableView.ReloadData();
                var oldFrame = _fromAutoCompleteTableView.Frame;
                _fromAutoCompleteTableView.Frame  = new CGRect(oldFrame.Left, oldFrame.Top, oldFrame.Width, suggestions.Count() * 30f);
                _fromAutoCompleteTableView.Hidden = false;
            }
            else
            {
                _fromAutoCompleteTableView.Hidden = true;
            }
        }
Beispiel #18
0
        private async void search_TextChanged(object s, AutoSuggestBoxTextChangedEventArgs args)
        {
            AutoSuggestBox sender = (AutoSuggestBox)s;

            // Only get results when it was a user typing,
            // otherwise assume the value got filled in by TextMemberPath
            // or the handler for SuggestionChosen.
            if (args.Reason == AutoSuggestionBoxTextChangeReason.UserInput)
            {
                if (string.IsNullOrWhiteSpace(sender.Text))
                {
                    sender.ItemsSource = null;
                }
                else
                {
                    var suggestions = await GeocodeHelper.SuggestAsync(sender.Text);

                    sender.ItemsSource = suggestions.ToList();
                }
            }
        }
Beispiel #19
0
        private void btnThaiWikipedia_Click(Object sender, EventArgs e)
        {
            var item = lbxNames.SelectedItem as EntityList;

            if (item != null)
            {
                var provinces     = allEntities.Where(x => x.type.IsCompatibleEntityType(EntityType.Changwat));
                var allAmphoe     = allEntities.Where(x => x.type.IsCompatibleEntityType(EntityType.Amphoe));
                var provincesUsed = item.Entities.SelectMany(x => provinces.Where(y => GeocodeHelper.IsBaseGeocode(y.geocode, x.geocode))).ToList();

                var builder = new StringBuilder();
                builder.AppendFormat("'''{0}''' สามารถหมายถึง", item.Entities.First().FullName);
                builder.AppendLine();
                foreach (var subItem in item.Entities)
                {
                    var province = provinces.FirstOrDefault(x => GeocodeHelper.IsBaseGeocode(x.geocode, subItem.geocode));
                    var amphoe   = allAmphoe.FirstOrDefault(x => GeocodeHelper.IsBaseGeocode(x.geocode, subItem.geocode));
                    if (amphoe == null && subItem.type.IsLocalGovernment())
                    {
                        var firstTambonCode = subItem.LocalGovernmentAreaCoverage.First().geocode;
                        amphoe = allAmphoe.FirstOrDefault(x => GeocodeHelper.IsBaseGeocode(x.geocode, firstTambonCode));
                    }
                    var    parentInfo        = String.Format("{0} {1}", amphoe.FullName, province.FullName);
                    String disambiguatedName = String.Format("{0} ({1})", subItem.FullName, province.FullName);
                    if (provincesUsed.Count(x => x == province) > 1)
                    {
                        disambiguatedName = String.Format("{0} ({1})", subItem.FullName, amphoe.FullName);
                    }
                    builder.AppendFormat("* [[{0}|{1}]] {2}", disambiguatedName, subItem.FullName, parentInfo);
                    builder.AppendLine();
                }
                builder.AppendLine();
                builder.AppendLine("{{แก้กำกวม}}");

                Clipboard.Clear();
                Clipboard.SetText(builder.ToString());
            }
        }
Beispiel #20
0
        private async void RunMapRightTapped(MapControl sender, Geopoint Location)
        {
            InfoPane.IsPaneOpen = true;
            LastRightTap        = Location;
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async delegate
            {
                var t = (await ViewModel.PlaceControls.SearchHelper.NearbySearch(Location.Position, 5));
                if (t != null)
                {
                    var pic = t.results.Where(x => LastRightTap.DistanceTo(new Geopoint(new BasicGeoposition()
                    {
                        Latitude = x.geometry.location.lat, Longitude = x.geometry.location.lng
                    })) < 1)
                              .OrderBy(x => LastRightTap.DistanceTo(new Geopoint(new BasicGeoposition()
                    {
                        Latitude = x.geometry.location.lat, Longitude = x.geometry.location.lng
                    }))).FirstOrDefault();
                    //var pic = t.results.Where(x => x.photos != null).LastOrDefault();
                    if (pic != null)
                    {
                        LastPlaceID = pic.place_id;
                        if (pic.photos != null)
                        {
                            PlaceImage.Source = new BitmapImage()
                            {
                                UriSource = ViewModel.PhotoControls.PhotosHelper.GetPhotoUri(pic.photos.FirstOrDefault().photo_reference, 350, 350)
                            };
                        }
                        var det = await ViewModel.PlaceControls.PlaceDetailsHelper.GetPlaceDetails(pic.place_id);
                        if (det != null)
                        {
                            PlaceAddress.Text = det.result.formatted_address;
                            PlaceName.Text    = det.result.name;
                            if (det.result.formatted_phone_number != null)
                            {
                                PlacePhone.Text          = det.result.formatted_phone_number;
                                PlacePhoneItem.IsEnabled = true;
                            }
                            if (det.result.website != null)
                            {
                                PlaceWebSite.Text          = det.result.website;
                                PlaceWebSiteItem.IsEnabled = true;
                            }
                            if (det.result.opening_hours != null)
                            {
                                var hours    = det.result.opening_hours.weekday_text;
                                string MyStr = "Is open : " + det.result.opening_hours.open_now;
                                if (hours != null)
                                {
                                    foreach (var item in hours)
                                    {
                                        MyStr += Environment.NewLine + item;
                                    }
                                }
                                PlaceOpenNow.Text          = MyStr;
                                PlaceOpenNowItem.IsEnabled = true;
                            }
                            PlaceRate.Text          = det.result.rating.ToString();
                            PlaceRateItem.IsEnabled = true;
                            if (det.result.reviews != null)
                            {
                                PlaceReviewsItem.ItemsSource = det.result.reviews;
                                PlaceReviewsItem.IsEnabled   = true;
                            }
                        }
                        else
                        {
                            PlaceName.Text    = pic.name;
                            PlaceAddress.Text = pic.vicinity;
                        }
                    }
                    //else
                    //{
                    //    var res = (await GeocodeHelper.GetInfo(Location)).results.FirstOrDefault();
                    //    if (res != null)
                    //    {
                    //        PlaceName.Text = res.address_components.FirstOrDefault().short_name;
                    //        PlaceAddress.Text = res.formatted_address;
                    //    }
                    //    else
                    //    {
                    //        await new MessageDialog("We didn't find anything here. Maybe an internet connection issue.").ShowAsync();
                    //        InfoPane.IsPaneOpen = false;
                    //    }
                    //}
                }
                else
                {
                    await new MessageDialog("We didn't find anything here. Maybe an internet connection issue.").ShowAsync();
                    InfoPane.IsPaneOpen = false;
                    return;

                    var r1 = (await GeocodeHelper.GetInfo(Location));
                    if (r1 != null)
                    {
                        var res = r1.results.FirstOrDefault();
                        if (res != null)
                        {
                            PlaceName.Text    = res.address_components.FirstOrDefault().short_name;
                            PlaceAddress.Text = res.formatted_address;
                        }
                        else
                        {
                            await new MessageDialog("We didn't find anything here. Maybe an internet connection issue.").ShowAsync();
                            InfoPane.IsPaneOpen = false;
                        }
                    }
                    else
                    {
                        await new MessageDialog("We didn't find anything here. Maybe an internet connection issue.").ShowAsync();
                        InfoPane.IsPaneOpen = false;
                    }
                }
            });
        }
Beispiel #21
0
        public async Task <IActionResult> Create([Bind("Id,Address1,Address2,AllergiesDescription,AttendHostChurch,City,ClassroomId,DateOfBirth,DecisionMade,EmergencyContactFirstName,EmergencyContactLastName,EmergencyContactPhone,EmergencyContactChildRelationship,FirstName,Gender,GradeCompleted,GuardianChildRelationship,GuardianEmail,GuardianFirstName,GuardianLastName,GuardianPhone,HomeChurch,InvitedBy,LastName,MedicalConditionDescription,MedicationDescription,PlaceChildWithRequest,SessionId,State,Zip")] CreateChildViewModel childVM)
        {
            if (ModelState.IsValid)
            {
                Child child = new Child
                {
                    VBSId = this.CurrentVBSId,
                    DateOfRegistration   = DateTime.UtcNow,
                    Address1             = childVM.Address1,
                    Address2             = childVM.Address2,
                    AllergiesDescription = childVM.AllergiesDescription,
                    AttendHostChurch     = childVM.AttendHostChurch,
                    City         = childVM.City,
                    ClassroomId  = childVM.ClassroomId,
                    DateOfBirth  = childVM.DateOfBirth,
                    DecisionMade = childVM.DecisionMade,
                    EmergencyContactFirstName         = childVM.EmergencyContactFirstName,
                    EmergencyContactLastName          = childVM.EmergencyContactLastName,
                    EmergencyContactPhone             = childVM.EmergencyContactPhone,
                    EmergencyContactChildRelationship = childVM.EmergencyContactChildRelationship,
                    FirstName                   = childVM.FirstName,
                    Gender                      = childVM.Gender,
                    GradeCompleted              = childVM.GradeCompleted,
                    GuardianChildRelationship   = childVM.GuardianChildRelationship,
                    GuardianEmail               = childVM.GuardianEmail,
                    GuardianFirstName           = childVM.GuardianFirstName,
                    GuardianLastName            = childVM.GuardianLastName,
                    GuardianPhone               = childVM.GuardianPhone,
                    HomeChurch                  = childVM.HomeChurch,
                    InvitedBy                   = childVM.InvitedBy,
                    HasAllergies                = false,
                    HasMedicalCondition         = false,
                    HasMedications              = false,
                    LastName                    = childVM.LastName,
                    MedicalConditionDescription = childVM.MedicalConditionDescription,
                    MedicationDescription       = childVM.MedicationDescription,
                    PlaceChildWithRequest       = childVM.PlaceChildWithRequest,
                    SessionId                   = childVM.SessionId,
                    State = childVM.State,
                    Zip   = childVM.Zip
                };

                GetGeoCodeResponse geoResponse = await GeocodeHelper.GetGeoCode(child);

                if (geoResponse != null)
                {
                    child.Latitude  = geoResponse.Lat;
                    child.Longitude = geoResponse.Long;
                }

                if (child.ClassroomId == 0)
                {
                    child.ClassroomId = null;
                }

                _context.Add(child);
                await _context.SaveChangesAsync();

                childVM.Id = child.Id;
                return(RedirectToAction("Index"));
            }

            List <Classroom> classrooms = _context.Classes
                                          .Include(c => c.Session)
                                          .Where(c => c.VBSId == this.CurrentVBSId)
                                          .OrderBy(c => c.Session.Period)
                                          .ThenBy(c => c.Grade)
                                          .ThenBy(c => c.Name)
                                          .ToList();

            SelectListItem noneClassSelectItem = new SelectListItem {
                Value = "0", Text = "None", Selected = true
            };
            List <SelectListItem> assignClassrooms = new List <SelectListItem>();

            assignClassrooms.Add(noneClassSelectItem);

            foreach (Classroom dbClass in classrooms)
            {
                SelectListItem assignClass = new SelectListItem();
                assignClass.Value = dbClass.Id.ToString();
                assignClass.Text  = dbClass.Session.Period + " " + dbClass.Grade.GetDisplayName() + " " + dbClass.Name;
                assignClassrooms.Add(assignClass);
            }

            childVM.ClassroomSelectItems = assignClassrooms;

            ViewData["SessionId"] = new SelectList(_context.Sessions.Where(s => s.VBSId == this.CurrentVBSId), "Id", "Period", childVM.SessionId);
            return(View(childVM));
        }
Beispiel #22
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Address1,Address2,AllergiesDescription,AttendHostChurch,City,ClassroomId,DateOfBirth,DecisionMade,EmergencyContactFirstName,EmergencyContactLastName,EmergencyContactPhone,EmergencyContactChildRelationship,FirstName,Gender,GradeCompleted,GuardianChildRelationship,GuardianEmail,GuardianFirstName,GuardianLastName,GuardianPhone,HasAllergies,HasMedicalCondition,HasMedications,HomeChurch,InvitedBy,LastName,MedicalConditionDescription,MedicationDescription,PlaceChildWithRequest,SessionId,State,Zip")] EditChildViewModel childVM)
        {
            if (id != childVM.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                var child = await _context.Children
                            .Where(c => c.Id == childVM.Id && c.VBSId == this.CurrentVBSId && c.VBS.TenantId == this.TenantId)
                            .SingleOrDefaultAsync();

                child.VBSId                = this.CurrentVBSId;
                child.Address1             = childVM.Address1;
                child.Address2             = childVM.Address2;
                child.AllergiesDescription = childVM.AllergiesDescription;
                child.AttendHostChurch     = childVM.AttendHostChurch;
                child.City         = childVM.City;
                child.ClassroomId  = childVM.ClassroomId;
                child.DateOfBirth  = childVM.DateOfBirth;
                child.DecisionMade = childVM.DecisionMade;
                child.EmergencyContactFirstName         = childVM.EmergencyContactFirstName;
                child.EmergencyContactLastName          = childVM.EmergencyContactLastName;
                child.EmergencyContactPhone             = childVM.EmergencyContactPhone;
                child.EmergencyContactChildRelationship = childVM.EmergencyContactChildRelationship;
                child.FirstName                   = childVM.FirstName;
                child.Gender                      = childVM.Gender;
                child.GradeCompleted              = childVM.GradeCompleted;
                child.GuardianChildRelationship   = childVM.GuardianChildRelationship;
                child.GuardianEmail               = childVM.GuardianEmail;
                child.GuardianFirstName           = childVM.GuardianFirstName;
                child.GuardianLastName            = childVM.GuardianLastName;
                child.GuardianPhone               = childVM.GuardianPhone;
                child.HomeChurch                  = childVM.HomeChurch;
                child.InvitedBy                   = childVM.InvitedBy;
                child.HasAllergies                = false;
                child.HasMedicalCondition         = false;
                child.HasMedications              = false;
                child.LastName                    = childVM.LastName;
                child.MedicalConditionDescription = childVM.MedicalConditionDescription;
                child.MedicationDescription       = childVM.MedicationDescription;
                child.PlaceChildWithRequest       = childVM.PlaceChildWithRequest;
                child.SessionId                   = childVM.SessionId;
                child.State = childVM.State;
                child.Zip   = childVM.Zip;

                GetGeoCodeResponse geoResponse = await GeocodeHelper.GetGeoCode(child);

                if (geoResponse != null)
                {
                    child.Latitude  = geoResponse.Lat;
                    child.Longitude = geoResponse.Long;
                }


                if (child.ClassroomId == 0)
                {
                    child.ClassroomId = null;
                }

                try
                {
                    _context.Update(child);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ChildExists(child.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index"));
            }

            List <Classroom> classrooms = _context.Classes
                                          .Include(c => c.Session)
                                          .Where(c => c.VBSId == this.CurrentVBSId)
                                          .OrderBy(c => c.Session.Period)
                                          .ThenBy(c => c.Grade)
                                          .ThenBy(c => c.Name)
                                          .ToList();

            SelectListItem noneClassSelectItem = new SelectListItem {
                Value = "0", Text = "None", Selected = true
            };
            List <SelectListItem> assignClassrooms = new List <SelectListItem>();

            assignClassrooms.Add(noneClassSelectItem);

            foreach (Classroom dbClass in classrooms)
            {
                SelectListItem assignClass = new SelectListItem();
                assignClass.Value = dbClass.Id.ToString();
                assignClass.Text  = dbClass.Session.Period + " " + dbClass.Grade.GetDisplayName() + " " + dbClass.Name;
                assignClassrooms.Add(assignClass);
            }

            childVM.ClassroomSelectItems = assignClassrooms;

            ViewData["SessionId"] = new SelectList(_context.Sessions.Where(s => s.VBSId == this.CurrentVBSId), "Id", "Period", childVM.SessionId);
            return(View(childVM));
        }
Beispiel #23
0
        private async void OriginTxt_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args)
        {
            var pre = args.SelectedItem as PlaceAutoComplete.Prediction;

            if (pre == null)
            {
                return;
            }
            sender.Text = pre.description;

            if (pre.description == "MyLocation")
            {
                if (sender.Name == "OriginTxt")
                {
                    var p = (await ViewModel.MapViewVM.GeoLocate.GetGeopositionAsync()).Coordinate.Point;
                    DirectionsMainUserControl.Origin = p;
                    DirectionsMainUserControl.AddPointer(p, "Origin");
                }
                else if (sender.Name == "DestTxt")
                {
                    var p = (await ViewModel.MapViewVM.GeoLocate.GetGeopositionAsync()).Coordinate.Point;
                    DirectionsMainUserControl.Destination = p;
                    DirectionsMainUserControl.AddPointer(p, "Destination");
                }
                else
                {
                    var index = sender.Name.Replace("WayPoint", string.Empty);
                    DirectionsMainUserControl.WayPoints[Convert.ToInt32(index)] = (await ViewModel.MapViewVM.GeoLocate.GetGeopositionAsync()).Coordinate.Point;
                }
            }
            else if (pre.description.StartsWith("Saved:"))
            {
                var savedplaces = SavedPlacesVM.GetSavedPlaces();
                var res         = savedplaces.Where(x => x.PlaceName == pre.description.Replace("Saved:", string.Empty)).FirstOrDefault();
                if (sender.Name == "OriginTxt")
                {
                    var p = new Geopoint(new BasicGeoposition()
                    {
                        Latitude = res.Latitude, Longitude = res.Longitude
                    });
                    DirectionsMainUserControl.Origin = p;
                    DirectionsMainUserControl.AddPointer(p, "Origin");
                }
                else if (sender.Name == "DestTxt")
                {
                    var p = new Geopoint(new BasicGeoposition()
                    {
                        Latitude = res.Latitude, Longitude = res.Longitude
                    });
                    DirectionsMainUserControl.Destination = p;
                    DirectionsMainUserControl.AddPointer(p, "Destination");
                }
                else
                {
                    var index = sender.Name.Replace("WayPoint", string.Empty);
                    DirectionsMainUserControl.WayPoints[Convert.ToInt32(index)] = new Geopoint(new BasicGeoposition()
                    {
                        Latitude = res.Latitude, Longitude = res.Longitude
                    });
                }
            }
            else
            {
                var res = await GeocodeHelper.GetInfo(pre.place_id);

                if (res == null)
                {
                    return;
                }
                var ploc = res.results.FirstOrDefault().geometry.location;
                if (sender.Name == "OriginTxt")
                {
                    var p = new Geopoint(new BasicGeoposition()
                    {
                        Latitude = ploc.lat, Longitude = ploc.lng
                    });
                    DirectionsMainUserControl.Origin = p;
                    DirectionsMainUserControl.AddPointer(p, "Origin");
                }
                else if (sender.Name == "DestTxt")
                {
                    var p = new Geopoint(new BasicGeoposition()
                    {
                        Latitude = ploc.lat, Longitude = ploc.lng
                    });
                    DirectionsMainUserControl.Destination = p;
                    DirectionsMainUserControl.AddPointer(p, "Destination");
                }
                else
                {
                    var index = sender.Name.Replace("WayPoint", string.Empty);
                    DirectionsMainUserControl.WayPoints[Convert.ToInt32(index)] = new Geopoint(new BasicGeoposition()
                    {
                        Latitude = ploc.lat, Longitude = ploc.lng
                    });
                }
            }
        }
Beispiel #24
0
        // GET: Map of registered children
        public async Task <IActionResult> ChildrenMap()
        {
            var applicationDbContext = _context.Children
                                       .Where(c => c.VBSId == this.CurrentVBSId && c.VBS.TenantId == this.TenantId);

            List <Child> dbChildren = await applicationDbContext.ToListAsync();

            Dictionary <string, string> addressList = new Dictionary <string, string>();
            string markers = "[";

            foreach (Child child in dbChildren)
            {
                string childAddress = GeocodeHelper.GetFullAddress(child);

                if (string.IsNullOrWhiteSpace(child.Latitude) || string.IsNullOrWhiteSpace(child.Longitude))
                {
                    var response = await GeocodeHelper.GetGeoCode(childAddress);

                    if (response != null)
                    {
                        child.Latitude  = response.Lat;
                        child.Longitude = response.Long;
                        _context.Update(child);
                        await _context.SaveChangesAsync();
                    }
                }


                if (!addressList.ContainsKey(childAddress))
                {
                    addressList.Add(childAddress, child.LastName);

                    string homeChurch;

                    if (child.AttendHostChurch)
                    {
                        homeChurch = "home";
                    }
                    else
                    {
                        if (ChurchHelper.IsNoneChurch(child.HomeChurch))
                        {
                            homeChurch = "none";
                        }
                        else
                        {
                            homeChurch = "other";
                        }
                    }

                    markers += "{";
                    markers += string.Format("'title': '{0}',", System.Net.WebUtility.HtmlEncode(child.LastName));
                    markers += string.Format("'lat': '{0}',", child.Latitude);
                    markers += string.Format("'lng': '{0}',", child.Longitude);
                    markers += string.Format("'description': '{0}',", System.Net.WebUtility.HtmlEncode(childAddress));
                    markers += string.Format("'homeChurch': '{0}'", homeChurch);
                    markers += "},";
                }
            }

            markers += "];";

            ViewBag.Markers = markers;

            ChildrenMapViewModel vm = new ChildrenMapViewModel();

            vm.ChurchName = "Northwest Bible Church";

            return(View(vm));
        }
Beispiel #25
0
        private void btnLaoList_Click(object sender, EventArgs e)
        {
            StringBuilder result = new StringBuilder();
            var           codes  = new List <String>();

            foreach (var province in allEntities.Where(x => x.type == EntityType.Changwat))
            {
                result.AppendFormat(CultureInfo.InvariantCulture, "* '''{0}''': ", province.EnglishFullName);
                codes.Clear();
                var localGovernment = allEntities.Where(x => !x.IsObsolete && x.type.IsLocalGovernment() && GeocodeHelper.IsBaseGeocode(province.geocode, x.geocode));
                foreach (var lao in localGovernment)
                {
                    if (lao.wiki != null && !String.IsNullOrEmpty(lao.wiki.wikidata))
                    {
                        // codes.Add(String.Format("{{{{Q|{0}}}}}", tambon.wiki.wikidata.Remove(0, 1)));
                        codes.Add(String.Format(CultureInfo.InvariantCulture, "[[{0}]]", lao.wiki.wikidata));
                    }
                    else
                    {
                        codes.Add(lao.english);
                    }
                }
                result.AppendLine(String.Join(" - ", codes));
            }
            edtCollisions.Text = result.ToString();
        }
        private async void Control2_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args)
        {
            var select = (args.SelectedItem as PlaceAutoComplete.Prediction);

            if (select == null)
            {
                return;
            }
            if (select.description.StartsWith("Saved:"))
            {
                SearchBox.Text = "";
                var loc = select.place_id.Split(',');
                var lat = loc[0]; var lng = loc[1];
                MapView.MapControl.Center = new Geopoint(
                    new BasicGeoposition()
                {
                    Latitude  = Convert.ToDouble(lat),
                    Longitude = Convert.ToDouble(lng)
                });
                MapView.StaticMapView.SearchResultPoint = new Geopoint(
                    new BasicGeoposition()
                {
                    Latitude  = Convert.ToDouble(lat),
                    Longitude = Convert.ToDouble(lng)
                });
                (DataContext as ViewModel).SearchResults.Clear();
                SearchBox.Text = "";
                return;
            }
            if (select.description.StartsWith("Contacts:"))
            {
                var Addres = await SearchHelper.TextSearch(select.place_id);

                if (Addres != null)
                {
                    if (Addres.results != null && Addres.results.Any())
                    {
                        var loc = Addres.results.FirstOrDefault().geometry.location;
                        MapView.MapControl.Center = new Geopoint(
                            new BasicGeoposition()
                        {
                            Latitude  = loc.lat,
                            Longitude = loc.lng
                        });
                        MapView.StaticMapView.SearchResultPoint = new Geopoint(
                            new BasicGeoposition()
                        {
                            Latitude  = loc.lat,
                            Longitude = loc.lng
                        });
                        (DataContext as ViewModel).SearchResults.Clear();
                        SearchBox.Text = "";
                    }
                }
                return;
            }
            var res = await GeocodeHelper.GetInfo(select.place_id);

            SearchBox.Text = "";
            if (res == null || res.results.Length == 0)
            {
                await new MessageDialog("We couldn't find place location!").ShowAsync();
                return;
            }
            var ploc = res.results.FirstOrDefault().geometry.location;

            MapView.MapControl.Center = new Geopoint(
                new BasicGeoposition()
            {
                Latitude  = ploc.lat,
                Longitude = ploc.lng
            });
            MapView.StaticMapView.SearchResultPoint = new Geopoint(
                new BasicGeoposition()
            {
                Latitude  = ploc.lat,
                Longitude = ploc.lng
            });
            (DataContext as ViewModel).SearchResults.Clear();
            //SearchReq.Invoke(args.SelectedItem as ClassProduct.Product, null);
            //SearchBox.Visibility = Visibility.Collapsed;
            //BTNExpand.Visibility = Visibility.Visible;
        }