public async Task <IActionResult> SetCurrentLocationForUser([FromBody] UserCurrentLocationUpdate userCurrentLocation) { // TODO: validation, return BadRequest _logger.LogInformation($"{nameof(SetCurrentLocationForUser)}: Id: {userCurrentLocation.Id}, Lat: {userCurrentLocation.CurrentLocation.Latitude}, Long: {userCurrentLocation.CurrentLocation.Longitude}"); var result = await _userLocationService.SetCurrentLocationForUserAsync(userCurrentLocation); if (result.Success) { return(CreatedAtAction(nameof(SetCurrentLocationForUser), result.Model)); } return(StatusCode(500)); }
public async Task <OperationResult <UserCurrentLocation> > SetCurrentLocationForUserAsync(UserCurrentLocationUpdate model) { var success = false; var userCurrentLocation = new UserCurrentLocation(); try { userCurrentLocation.Id = model.Id; userCurrentLocation.CurrentLocation = model.CurrentLocation; userCurrentLocation.TimeAtLocation = DateTime.UtcNow; await UpdateCurrentLocationForUser(userCurrentLocation); await UpdateLocationHistoryForUser(userCurrentLocation); await UpdateAllUsersCurrentLocation(userCurrentLocation); success = true; } catch (Exception ex) { _logger.LogError(ex, $"{nameof(SetCurrentLocationForUserAsync)} - {model.Id}"); } return(new OperationResult <UserCurrentLocation>() { Success = success, Model = userCurrentLocation }); }