public ActionResult UpdateUserGeolocation([FromRoute] string userId, [FromBody] UpdateUserLocationModel updateUserLocation) { try { var userLocation = _mapsStorageService.UpdateUserLocation(userId, updateUserLocation); _azureMapsApiService.NotifyUserGeoposition(userLocation); return(Ok()); } catch (UserNotFoundException e) { return(BadRequest(e.Message)); } }
public UserLocationModel UpdateUserLocation(string userId, UpdateUserLocationModel updateUserLocation) { ClearExpiredUsers(); var storedUserLocation = UsersLocations.FirstOrDefault(user => string.Equals(user.Id, userId, StringComparison.OrdinalIgnoreCase)); if (storedUserLocation == null) { throw new UserNotFoundException($"User not found with the id: {userId}"); } var currentPosition = new GeoCoordinateModel(storedUserLocation.Latitude, storedUserLocation.Longitude); GeoCoordinateModel newPosition = null; switch (updateUserLocation.Direction) { case Direction.North: newPosition = currentPosition.CalculateDerivedPosition(_azureMapsOptions.UserStepDistanceInMeters, 0); break; case Direction.South: newPosition = currentPosition.CalculateDerivedPosition(_azureMapsOptions.UserStepDistanceInMeters, 180); break; case Direction.West: newPosition = currentPosition.CalculateDerivedPosition(_azureMapsOptions.UserStepDistanceInMeters, -90); break; case Direction.East: newPosition = currentPosition.CalculateDerivedPosition(_azureMapsOptions.UserStepDistanceInMeters, 90); break; } storedUserLocation.Latitude = newPosition.Latitude; storedUserLocation.Longitude = newPosition.Longitude; storedUserLocation.LastUpdated = DateTime.Now; return(storedUserLocation); }