Ejemplo n.º 1
0
        public async Task <IEnumerable <NoteViewModel> > Nearby(ApplicationUser applicationUser, NoteSearchRequest noteSearchRequest)
        {
            var geoCodeRange = GeolocationHelpers.CalculateGeoCodeRange(noteSearchRequest.LatitudeD, noteSearchRequest.LongitudeD, noteSearchRequest.RangeKmD,
                                                                        GeolocationHelpers.DistanceType.Kilometers);

            var orderedNearbyNotes = await _dbContext.Notes
                                     .Include(n => n.User)
                                     .Include(n => n.Votes)
                                     .Include(n => n.ReportedNotes)
                                     .WhereInGeoCodeRange(new GeoCodeRange
            {
                MinimumLatitude  = geoCodeRange.MinimumLatitude,
                MaximumLatitude  = geoCodeRange.MaximumLatitude,
                MinimumLongitude = geoCodeRange.MinimumLongitude,
                MaximumLongitude = geoCodeRange.MaximumLongitude,
            })
                                     .Where(n => !n.IsDeleted)
                                     .OrderBy(n =>
                                              GeolocationHelpers.CalculateDistance(
                                                  n.LatitudeD, n.LongitudeD,
                                                  noteSearchRequest.LatitudeD,
                                                  noteSearchRequest.LongitudeD,
                                                  GeolocationHelpers.DistanceType.Kilometers))
                                     .ThenByDescending(n => n.Id)
                                     .Take(noteSearchRequest.Take)
                                     .ToListAsync();

            return(await ConvertToViewableNotes(applicationUser, orderedNearbyNotes));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Nearby([FromBody] NoteSearchRequest noteSearchRequest)
        {
            var nearybyNotes = await _noteService.Nearby(ApplicationUser, noteSearchRequest).ConfigureAwait(false);

            return(Ok(nearybyNotes));
        }