private void GetLatLon(Location location) { if (Convert.ToDouble(location.Latitude) == 0 && Convert.ToDouble(location.Longitude) == 0) { try { var stateCode = _context.Lststate.Find(location.StateId).Name; var cityName = _context.Lstcity.Find(location.CityId).Name; var zipCode = _context.Lstpincode.Find(location.PincodeId).PinCode; double latitude; double longitude; GoogleLocationService.GetLanLon(GoogleLocationService.GoogleAddress(location.Address, cityName, stateCode, zipCode), out latitude, out longitude); location.Latitude = latitude; location.Longitude = longitude; _context.SaveChanges(); _context.Entry(location).State = EntityState.Detached; } catch (Exception ex) { _logger.LogError(ex, "GetLatLon"); } } }