public async Task <IActionResult> GetCurrentLocationForUsersInArea([FromBody] AreaBoundary areaBoundary)
        {
            _logger.LogInformation($"{nameof(GetCurrentLocationForUsersInArea)}");
            var result = await _userLocationService.GetCurrentLocationForUsersInAreaAsync(areaBoundary);

            if (result.Success)
            {
                return(Ok(result.Model));
            }

            return(StatusCode(500));
        }
Beispiel #2
0
 public BossBoundaryEntry(uint bossId, AreaBoundary boundary)
 {
     BossId   = bossId;
     Boundary = boundary;
 }
        public async Task <OperationResult <List <UserCurrentLocation> > > GetCurrentLocationForUsersInAreaAsync(AreaBoundary areaBoundary)
        {
            try
            {
                var allUsersCurrentLocation = await GetAllUsersCurrentLocation();

                var leftBoundary  = 0D;
                var rightBoundary = 0D;

                // TODO: This logic needs checking - check for libraries/better data types for geolocation
                if (Math.Abs(areaBoundary.WesternBoundary) <= 90 && Math.Abs(areaBoundary.EasternBoundary) <= 90)
                {
                    if ((areaBoundary.WesternBoundary < areaBoundary.EasternBoundary))
                    {
                        leftBoundary  = areaBoundary.WesternBoundary;
                        rightBoundary = areaBoundary.EasternBoundary;
                    }
                    else
                    {
                        leftBoundary  = areaBoundary.EasternBoundary;
                        rightBoundary = areaBoundary.WesternBoundary;
                    }
                }
                else
                {
                    if ((areaBoundary.WesternBoundary > areaBoundary.EasternBoundary))
                    {
                        leftBoundary  = areaBoundary.WesternBoundary;
                        rightBoundary = areaBoundary.EasternBoundary;
                    }
                    else
                    {
                        leftBoundary  = areaBoundary.EasternBoundary;
                        rightBoundary = areaBoundary.WesternBoundary;
                    }
                }

                var usersInArea = allUsersCurrentLocation
                                  .Where(u => u.CurrentLocation.Latitude < areaBoundary.NorthernBoundary)
                                  .Where(u => u.CurrentLocation.Latitude > areaBoundary.SouthernBoundary)
                                  .Where(u => (u.CurrentLocation.Longitude > leftBoundary) || (u.CurrentLocation.Longitude < rightBoundary))
                                  .ToList();

                return(new OperationResult <List <UserCurrentLocation> >()
                {
                    Success = true,
                    Model = usersInArea
                });
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, nameof(GetCurrentLocationForAllUsersAsync));
            }

            return(new OperationResult <List <UserCurrentLocation> >()
            {
                Success = false,
                Model = new List <UserCurrentLocation>()
            });
        }