public ActionResult Create([Bind(Include = "AdresID,KodPocztowy,Kraj,Miasto,Ulica,NrBudynku,NrLokalu")] Adres adres, long? id, KomuAdres komu) { if (Session["Auth"] != null) { if (Session["Auth"].ToString() == "Recepcjonista" || Session["Auth"].ToString() == "Administrator") { object redirectTo = null; if (ModelState.IsValid) { switch (komu) { case KomuAdres.Osoba: Osoba osoba = db.Osoby.Find(id); redirectTo = osoba.GetType().BaseType.Name; osoba.Adres = adres; //Google Maps var locationServiceO = new GoogleLocationService(); AddressData adrO = new AddressData(); adrO.Country = adres.Kraj; adrO.City = adres.Miasto; adrO.Zip = adres.KodPocztowy; adrO.Address = adres.Ulica + " " + adres.NrBudynku + " " + adres.NrLokalu; var pointO = locationServiceO.GetLatLongFromAddress(adrO); osoba.Szerokosc = pointO.Longitude; osoba.Dlugosc = pointO.Latitude; redirectTo = osoba.GetType().BaseType.Name; //adres.Osoba = osoba; break; case KomuAdres.Silownia: Silownia.Models.Silownia silownia = db.Silownie.Find(id); silownia.Adres = adres; var locationServiceS = new GoogleLocationService(); AddressData adrS = new AddressData(); adrS.Country = adres.Kraj; adrS.City = adres.Miasto; adrS.Zip = adres.KodPocztowy; adrS.Address = adres.Ulica + " " + adres.NrBudynku + " " + adres.NrLokalu; var pointS = locationServiceS.GetLatLongFromAddress(adrS); silownia.Szerokosc = pointS.Longitude; silownia.Dlugosc = pointS.Latitude; redirectTo = silownia.GetType().BaseType.Name; break; } db.Adresy.Add(adres); db.SaveChanges(); return RedirectToAction("Index", redirectTo.ToString()); } return View(adres); } } return HttpNotFound(); }
/// <summary> /// Gets an array of string addresses that matched a possibly ambiguous address. /// </summary> /// <param name="address">The address.</param> /// <returns></returns> /// <exception cref="System.Net.WebException"></exception> public string[] GetAddressesListFromAddress(AddressData address) { return(GetAddressesListFromAddress(address.ToString())); }
/// <summary> /// Gets the latitude and longitude that belongs to an address. /// </summary> /// <param name="address">The address.</param> /// <returns></returns> public MapPoint GetLatLongFromAddress(AddressData address) { return(GetLatLongFromAddress(address.ToString())); }
/// <summary> /// Gets the directions. /// </summary> /// <param name="originAddress">From address.</param> /// <param name="destinationAddress">To address.</param> /// <returns>The directions</returns> public Directions GetDirections(AddressData originAddress, AddressData destinationAddress) { Directions direction = new Directions(); XDocument xdoc = XDocument.Load(String.Format(APIUrlDirections, originAddress.ToString(), destinationAddress.ToString())); var status = (from s in xdoc.Descendants("DirectionsResponse").Descendants("status") select s).FirstOrDefault(); if (status != null && status.Value == "OK") { direction.StatusCode = Directions.Status.OK; var distance = (from d in xdoc.Descendants("DirectionsResponse").Descendants("route").Descendants("leg") .Descendants("distance").Descendants("text") select d).LastOrDefault(); if (distance != null) { direction.Distance = distance.Value; } var duration = (from d in xdoc.Descendants("DirectionsResponse").Descendants("route").Descendants("leg") .Descendants("duration").Descendants("text") select d).LastOrDefault(); if (duration != null) { direction.Duration = duration.Value; } var steps = from s in xdoc.Descendants("DirectionsResponse").Descendants("route").Descendants("leg").Descendants("step") select s; foreach (var step in steps) { Step directionStep = new Step(); directionStep.Instruction = step.Element("html_instructions").Value; directionStep.Distance = step.Descendants("distance").First().Element("text").Value; direction.Steps.Add(directionStep); } return direction; } else if (status != null && status.Value != "OK") { direction.StatusCode = Directions.Status.FAILED; return direction; } else { throw new Exception("Unable to get Directions from Google"); } }
/// <summary> /// Gets the latitude and longitude that belongs to an address. /// </summary> /// <param name="address">The address.</param> /// <returns></returns> public MapPoint GetLatLongFromAddress(AddressData address) { return GetLatLongFromAddress(address.ToString()); }
public async Task AddShopAsync(ClaimsPrincipal user, ShopViewModel shopViewModel) { Shop shop = new Shop(); var addressData = new AddressData { Address = shopViewModel.Address, City = shopViewModel.City.ToUpper(), Country = "Italy" }; var gls = new GoogleLocationService(); var latlong = gls.GetLatLongFromAddress(addressData); var latitude = latlong.Latitude; var longitude = latlong.Longitude; shop.Name = shopViewModel.Name; shop.ShortDesc = shopViewModel.ShortDesc; shop.City = shopViewModel.City; shop.Address = shopViewModel.Address; shop.Website = shopViewModel.Website; shop.Phone = shopViewModel.Phone; shop.Latitude = latitude; shop.Longitude = longitude; shop.InsertDate = DateTime.Now; shop.InsertUserId = user.GetUserId(); shop.UserId = user.GetUserId(); _dbContext.Shop.Add(shop); await _dbContext.SaveChangesAsync(); }