Exemple #1
0
        public async Task <IActionResult> Edit(int id, [Bind("NearbyPlacesId,next_page_token,status")] NearbyPlaces nearbyPlaces)
        {
            if (id != nearbyPlaces.NearbyPlacesId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(nearbyPlaces);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!NearbyPlacesExists(nearbyPlaces.NearbyPlacesId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(nearbyPlaces));
        }
Exemple #2
0
        public async Task <IActionResult> Create([Bind("NearbyPlacesId,next_page_token,status")] NearbyPlaces nearbyPlaces)
        {
            if (ModelState.IsValid)
            {
                _context.Add(nearbyPlaces);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(nearbyPlaces));
        }
        public async Task <NearbyPlaces> GetNearbyPlaces(string type, string coords, string radius)
        {
            string              url      = $"https://maps.googleapis.com/maps/api/place/nearbysearch/json?location={coords}&radius={radius}&type={type}&keyword=&key={APIKEYS.GoogleAPIKey}";
            HttpClient          client   = new HttpClient();
            HttpResponseMessage response = await client.GetAsync(url);

            if (response.IsSuccessStatusCode)
            {
                string json = await response.Content.ReadAsStringAsync();

                NearbyPlaces nearbyPlaces = JsonConvert.DeserializeObject <NearbyPlaces>(json);
                return(nearbyPlaces);
            }
            return(null);
        }
Exemple #4
0
        public async Task <IActionResult> PlaceSelection(MapViewModel mapView)
        {
            var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
            var viewer = _context.Viewers.Where(c => c.IdentityUserId == userId).SingleOrDefault();

            mapView.Viewer = viewer;
            var wWID    = _context.WWindow.Where(a => a.ViewerLocation.Viewer.ViewerId == viewer.ViewerId).Select(b => b.WWindowId).FirstOrDefault();
            var wWindow = _context.WWindow.Where(b => b.WWindowId == wWID).FirstOrDefault();
            var vLoc    = _context.ViewerLocation.Where(a => a.ViewerLocationViewerId == viewer.ViewerId).FirstOrDefault();

            wWindow.ViewerLocation = vLoc;
            mapView.Viewer.WWindow = wWindow;
            var          coords       = mapView.Viewer.WWindow.ViewerLocation.ViewerLocationLat + "," + mapView.Viewer.WWindow.ViewerLocation.ViewerLocationLong;
            var          radiusID     = mapView.Viewer.WWindow.TravelRadiusId;
            var          radius       = _context.TravelRadius.Where(a => a.TravelRadiusId == radiusID).Select(b => b.RadiumMeters).FirstOrDefault().ToString();
            NearbyPlaces nearbyPlaces = await _nearbySearchRequest.GetNearbyPlaces(mapView.SelectedPlace.GooglePlacesType, coords, radius);

            mapView.NearbyPlaces = nearbyPlaces;
            return(View("MapView", mapView));
        }
        public List <Place> LoadPlaces(Location location, int radius, RefreshType refreshType)
        {
            _lastRequest  = DateTime.Now;
            _lastLocation = location;
            _lastRadius   = radius;

            switch (refreshType)
            {
            case RefreshType.complete:
                SetOfNearbyPlaces = NearbyPlaces.GetNearbyPlaces(_apiKey, location, radius, NearbyPlaces.PlaceType.supermarket);
                break;

            case RefreshType.update:
                if (SetOfNearbyPlaces == null || SetOfNearbyPlaces.Count == 0)
                {
                    SetOfNearbyPlaces = NearbyPlaces.GetNearbyPlaces(_apiKey, location, radius, NearbyPlaces.PlaceType.supermarket);
                }
                else
                {
                    SetOfNearbyPlaces = NearbyPlaces.UpdateNearbyPlaces(_apiKey, location, radius, NearbyPlaces.PlaceType.supermarket, SetOfNearbyPlaces);
                }
                break;

            case RefreshType.partlyNew:
                if (SetOfNearbyPlaces == null || SetOfNearbyPlaces.Count == 0)
                {
                    SetOfNearbyPlaces = NearbyPlaces.GetNearbyPlaces(_apiKey, location, radius, NearbyPlaces.PlaceType.supermarket);
                }
                else
                {
                    SetOfNearbyPlaces = NearbyPlaces.UpdateNearbyPlaces(_apiKey, location, radius, NearbyPlaces.PlaceType.supermarket, SetOfNearbyPlaces);
                }
                break;

            default:
                return(null);
            }

            return(SetOfNearbyPlaces);
        }