Exemplo n.º 1
0
        private static LatLong GeoCodePostCode(string AddressToParse, string APIKey)
        {
            Geocoding.Microsoft.BingMapsGeocoder          geocoder  = new Geocoding.Microsoft.BingMapsGeocoder(APIKey);
            IEnumerable <Geocoding.Microsoft.BingAddress> addresses = geocoder.Geocode(AddressToParse);
            LatLong result = new LatLong();

            if (addresses != null && addresses.Any())
            {
                result.Lat  = addresses.First().Coordinates.Latitude;
                result.Long = addresses.First().Coordinates.Longitude;
            }
            else
            {
                result.Lat  = 0;
                result.Long = 0;
            }
            return(result);
        }
Exemplo n.º 2
0
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }
            Company Company = await _context.Company.Include(o => o.Resturaunts).FirstOrDefaultAsync(r => r.id == HttpContext.Session.GetInt32("company_id"));

            ResturauntPage resturauntPage = new ResturauntPage();

            resturauntPage.Days = new List <Day>();
            resturauntPage.Days.Add(new Day()
            {
                DayName = "Monday"
            });
            resturauntPage.Days.Add(new Day()
            {
                DayName = "Tuesday"
            });
            resturauntPage.Days.Add(new Day()
            {
                DayName = "Wednesday"
            });
            resturauntPage.Days.Add(new Day()
            {
                DayName = "Thursday"
            });
            resturauntPage.Days.Add(new Day()
            {
                DayName = "Friday"
            });
            resturauntPage.Days.Add(new Day()
            {
                DayName = "Saturday"
            });
            resturauntPage.Days.Add(new Day()
            {
                DayName = "Sunday"
            });
            resturauntPage.Image = new Image();

            Resturaunt.ResturauntPage = resturauntPage;

            String    Address  = Resturaunt.Address.AddressLine1 + " " + Resturaunt.Address.AddressLine2 + " " + Resturaunt.Address.City + " " + Resturaunt.Address.State + " " + Resturaunt.Address.Country + " " + Resturaunt.Address.Zip;
            IGeocoder geocoder = new Geocoding.Microsoft.BingMapsGeocoder("AqxoCm4UJW5_DXYlq73P9Vso_jGJl60qBQSZnt6VhtCv9wZSK2SbSAKq_ljydb6S");
            IEnumerable <Geocoding.Address> addresses = await geocoder.GeocodeAsync(Address);

            Models.Location location = new Models.Location();
            location.Lang = addresses.First().Coordinates.Latitude;
            location.Long = addresses.First().Coordinates.Longitude;


            Resturaunt.Location = location;

            Company.Resturaunts.Add(Resturaunt);
            _context.Resturaunt.Add(Resturaunt);
            location.ResturauntId = Resturaunt.id;
            _context.Location.Add(location);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }