public HttpResponseMessage PutUserGpsLocation([FromBody] UserLocationModel model, string uid) { try { LogRequest(model); if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } var nearByUser = new NearByUser() { UId = uid, Latitude = model.Latitude, Longitude = model.Longitude }; bool opertionResult = NearByMeManager.GetInstance().UpsertUserGpsLocation(nearByUser); if (!opertionResult) { return(Request.CreateResponse(HttpStatusCode.InternalServerError)); } return(Request.CreateResponse(HttpStatusCode.OK)); } catch (ApplicationException applicationException) { return(Request.CreateErrorResponse((HttpStatusCode)Convert.ToInt16(applicationException.Message), NeeoDictionaries.HttpStatusCodeDescriptionMapper[Convert.ToInt16(applicationException.Message)])); } catch (Exception exception) { Logger.LogManager.CurrentInstance.ErrorLogger.LogError(System.Reflection.MethodBase.GetCurrentMethod().GetType(), exception.Message, exception); return(Request.CreateResponse(HttpStatusCode.InternalServerError)); } }
public async Task <ActionResult> AddUserLocation([FromBody] UserLocationModel user) { try { var createdUser = userLocationServices.AddUserLocation(user); return(Ok(new { userLocation = createdUser })); } catch (Exception ex) { Logger.Error(ex); return(await Task.FromResult(BadRequest("Unable to process your request."))); } }
public async Task <IPeopleNearByResponse> AddUpdateUserLocation(UserLocationModel view) { try { logger.Info($"{ GetType().Name} { ExtensionUtility.GetCurrentMethod() } input: {view.ToJsonString()} UserIPAddress: { _userIPAddress.GetUserIP().Result }"); var firstName = await _appDbContext.Profiles.Where(k => k.Id == view.ProfileID).Select(k => k.FirstNameEn).FirstOrDefaultAsync(); var lastName = await _appDbContext.Profiles.Where(k => k.Id == view.ProfileID).Select(k => k.LastNameEn).FirstOrDefaultAsync(); var userName = firstName + " " + lastName; var data = await _appDbContext.UserLocations.FirstOrDefaultAsync(x => x.ProfileID == view.ProfileID); if (data == null) { data = new UserLocation() { ProfileID = view.ProfileID, Latitude = view.Latitude, Longitude = view.Longitude, isHideLocation = true, Created = DateTime.Now, LastUpdated = DateTime.Now, CreatedBy = userName, LastUpdatedBy = userName }; await _appDbContext.UserLocations.AddAsync(data); await _appDbContext.SaveChangesAsync(); } else { data.Latitude = view.Latitude; data.Longitude = view.Longitude; data.LastUpdated = DateTime.Now; await _appDbContext.SaveChangesAsync(); } var userLocation = _mapper.Map <UserLocationModelView>(data); return(new PeopleNearByResponse(userLocation)); } catch (Exception ex) { logger.Error(ex); throw ex; } }
public ActionResult RegisteredUserModel([FromBody] UserLocationModel userLocation) { if (string.IsNullOrEmpty(userLocation.Id)) { return(BadRequest("Id of the user is required.")); } if (string.IsNullOrEmpty(userLocation.Name)) { return(BadRequest("Name of the user is required.")); } userLocation.IsReal = true; // Set always to true if using this endpoint _mapsStorageService.Register(userLocation); return(Ok()); }
public ObservableCollection <TeamMemberModel> GetTestData() { var teamMemberModelList = new ObservableCollection <TeamMemberModel>(); var user = new User { Name = "Manny Singh" }; var userLocation = new UserLocationModel { Latitude = 32.8946723, Longitude = -96.9774144, AddressName = "Microsoft Las Colinas" }; teamMemberModelList.Add(new TeamMemberModel(user, userLocation)); user = new User { Name = "Chris Palmer" }; userLocation = new UserLocationModel { Latitude = 32.8946723, Longitude = -96.9774144, AddressName = "Microsoft Las Colinas" }; teamMemberModelList.Add(new TeamMemberModel(user, userLocation)); user = new User { Name = "Joseph Baggett" }; userLocation = new UserLocationModel { Latitude = 32.8959446, Longitude = -96.9597849, AddressName = "Starbucks" }; teamMemberModelList.Add(new TeamMemberModel(user, userLocation)); user = new User { Name = "Brent Finney" }; userLocation = new UserLocationModel { Latitude = 32.8946723, Longitude = -96.9774144, AddressName = "Microsoft Las Colinas." }; teamMemberModelList.Add(new TeamMemberModel(user, userLocation)); user = new User { Name = "Landry Kammogne" }; userLocation = new UserLocationModel { Latitude = 32.89109, Longitude = -96.962958, AddressName = "In Route" }; teamMemberModelList.Add(new TeamMemberModel(user, userLocation)); return(teamMemberModelList); }
//Function Handler is an entry point to start execution of Lambda Function. //It takes Input Data as First Parameter and ObjectContext as Second public async Task <object> FunctionHandler(UserLocationModel model, ILambdaContext context) { //Write Log to Cloud Watch using Console.WriteLline. Console.WriteLine("Execution started for function - {0} at {1}", context.FunctionName, DateTime.Now); // Create dynamodb client var dynamoDbClient = new AmazonDynamoDBClient( new AmazonDynamoDBConfig { //ServiceURL = _serviceUrl, RegionEndpoint = RegionEndpoint.USEast1, }); // Find favorite location for user LambdaLogger.Log("Find favorite location"); var locationChanges = await dynamoDbClient.GetItemAsync(new GetItemRequest { Key = new Dictionary <string, AttributeValue> { { "Username", new AttributeValue(model.Username.ToLowerInvariant()) } }, TableName = _tableName, ProjectionExpression = "RoomHistory" }); string favoriteRoom = null; if (locationChanges.IsItemSet && locationChanges.Item.ContainsKey("RoomHistory")) { List <string> rooms = locationChanges.Item["RoomHistory"] .L .Select(x => x.S) .ToList(); favoriteRoom = FindFavoriteRoom(rooms); } //Write Log to cloud watch using context.Logger.Log Method context.Logger.Log(string.Format("Finished execution for function -- {0} at {1}", context.FunctionName, DateTime.Now)); return(new { FavoriteRoom = favoriteRoom }); }
public HomeModel prepareHomeModel(string ipAddress) { HomeModel homeModel = new HomeModel(); string jsonObject = ApiCall.Request(IpLocationAddress, IpLocationPath); UserLocationModel userLocationModel = JsonConvert.DeserializeObject <UserLocationModel>(jsonObject); homeModel.UserLocation = userLocationModel.city + ", " + userLocationModel.country_name; homeModel.UserLatitude = Decimal.Parse(userLocationModel.latitude); homeModel.UserLongitude = Decimal.Parse(userLocationModel.longitude); homeModel.FeaturedEvents = eventRepository.GetFeaturedEvents(10).ToList(); homeModel.LatestEvents = eventRepository.GetEventsByPage(1, 10).ToList(); homeModel.MostInterested = eventRepository.getMostInterestedEvents(10).ToList(); homeModel.EventTypes = typeEventRepository.GetAll().ToList(); return(homeModel); }
public async Task NotifyUserGeoposition(UserLocationModel userLocation) { if (string.IsNullOrEmpty(_currentGeofenceUdId)) { return; } var queryString = HttpUtility.ParseQueryString(string.Empty); // Request parameters queryString["subscription-key"] = _azureMapsOptions.Key; queryString["api-version"] = _azureMapsOptions.ApiVersion; queryString["deviceId"] = userLocation.Name; queryString["udId"] = _currentGeofenceUdId; queryString["lat"] = $"{userLocation.Latitude}"; queryString["lon"] = $"{userLocation.Longitude}"; queryString["searchBuffer"] = "5"; queryString["isAsync"] = "True"; queryString["mode"] = "EnterAndExit"; var response = await Client.GetAsync($"{_azureMapsOptions.ApiEndpoint}/spatial/geofence/json?{queryString}"); response.EnsureSuccessStatusCode(); }
public void Register(UserLocationModel userLocation) { ClearExpiredUsers(); var storedUserLocation = UsersLocations.FirstOrDefault(user => string.Equals(user.Id, userLocation.Id, StringComparison.OrdinalIgnoreCase)); if (storedUserLocation == null) { userLocation.LastUpdated = DateTime.Now; UsersLocations.Add(userLocation); // Always generate new fake users after add the first user in the list. if (UsersLocations.Count == 1) { FakeUsers = GetFakeUsers(userLocation.Latitude, userLocation.Longitude); } } else { storedUserLocation.Latitude = userLocation.Latitude; storedUserLocation.Longitude = userLocation.Longitude; userLocation.LastUpdated = DateTime.Now; } }
//Function Handler is an entry point to start execution of Lambda Function. //It takes Input Data as First Parameter and ObjectContext as Second public async Task FunctionHandler(UserLocationModel locationModel, ILambdaContext context) { //Write Log to Cloud Watch using Console.WriteLline. Console.WriteLine("Execution started for function - {0} at {1}", context.FunctionName, DateTime.Now); // Create dynamodb client var dynamoDbClient = new AmazonDynamoDBClient( new AmazonDynamoDBConfig { //ServiceURL = _serviceUrl, RegionEndpoint = RegionEndpoint.USEast1, }); // Update location of user LambdaLogger.Log("Update location for record"); locationModel.Username = locationModel.Username.ToLowerInvariant(); locationModel.Room = locationModel.Room.ToLowerInvariant(); if (!locationModel.IsInOffice) { locationModel.Room = "out"; } else if (string.IsNullOrWhiteSpace(locationModel.Room)) { throw new ArgumentNullException("room"); } await dynamoDbClient.UpdateItemAsync(new UpdateItemRequest { Key = new Dictionary <string, AttributeValue> { { "Username", new AttributeValue(locationModel.Username) } }, TableName = _tableName, UpdateExpression = "SET IsInOffice = :o, Room = :r, RoomHistory = list_append(if_not_exists(RoomHistory, :empty_list), :room_history_record)" + (locationModel.IsInOffice ? ", LastTimeInOffice = :lt" : string.Empty), ConditionExpression = "Room <> :r", ExpressionAttributeValues = new Dictionary <string, AttributeValue> { { ":o", new AttributeValue { BOOL = locationModel.IsInOffice } }, { ":r", new AttributeValue { S = locationModel.Room } }, { ":room_history_record", new AttributeValue { L = new List <AttributeValue> { new AttributeValue { S = locationModel.Room } } } }, { ":empty_list", new AttributeValue { IsLSet = true } }, { ":lt", new AttributeValue { S = DateTime.Now.ToShortDateString() } } } }); //Write Log to cloud watch using context.Logger.Log Method context.Logger.Log(string.Format("Finished execution for function -- {0} at {1}", context.FunctionName, DateTime.Now)); }
public UserLocationModel GetUserLocation(string ipAddress) { if (string.IsNullOrEmpty(ipAddress)) { //return null; } string reqUrl = string.Format(ApiUrl, ipAddress); HttpWebRequest httpReq = HttpWebRequest.Create(reqUrl) as HttpWebRequest; try { string result = string.Empty; HttpWebResponse response = httpReq.GetResponse() as HttpWebResponse; using (var reader = new StreamReader(response.GetResponseStream())) { result = reader.ReadToEnd(); } // return ProcessResponse(result); StringReader sr = new StringReader(result); XElement respElement = XElement.Load(sr); UserLocationModel ulm = new UserLocationModel(); ulm.City = (string)respElement.Element("City"); ulm.Status = (string)respElement.Element("Status"); ulm.CountryCode = (string)respElement.Element("CountryCode"); ulm.CountryName = (string)respElement.Element("CountryName"); ulm.ZipPostalCode = (string)respElement.Element("ZipPostalCode"); ulm.RegionCode = (string)respElement.Element("RegionCode"); ulm.RegionName = (string)respElement.Element("RegionName"); ulm.Latitude = (string)respElement.Element("Latitude"); ulm.Longitude = (string)respElement.Element("Longitude"); ulm.Timezone = (string)respElement.Element("Timezone"); ulm.Gmtoffset = (string)respElement.Element("Gmtoffset"); ulm.Dstoffset = (string)respElement.Element("Dstoffset"); return ulm; } catch (Exception ex) { throw; } }
public Task <UserLocationModel> AddUserLocation(UserLocationModel userLocation) { return(_userLocationRepository.AddUserLocation(userLocation)); }
public async Task <IActionResult> AddUpdateUserLocation([FromBody] UserLocationModel view) { var result = await _peopleNearBy.AddUpdateUserLocation(view); return(Ok(result)); }
public async Task <IActionResult> Location([FromBody] UserLocationModel model) { var jwtToken = await _userService.SetLocationAsync(UserId, _mapper.Map <UserLocation>(model)); return(Success(jwtToken)); }