public async Task <Session> UpdateCosmosAsync(string sessionJson, Guid sessionId) { if (string.IsNullOrEmpty(sessionJson)) { return(null); } var response = await _documentDbProvider.UpdateSessionAsync(sessionJson, sessionId); var responseStatusCode = response?.StatusCode; return(responseStatusCode == HttpStatusCode.OK ? (dynamic)response.Resource : null); }
public async Task GenerateGeoCodingForSessionAsync() { Console.WriteLine("Starting Session GeoCoding Bulk Upload"); Console.WriteLine("Attempting to get GetSessionsWithVenuePostCode"); var sessions = await _dbProvider.GetSessionsWithVenuePostCodeAsync(); if (!sessions.Any()) { Console.WriteLine("No Sessions With Venue Postcodes to Update"); return; } Console.WriteLine("Sessions with Venue Postcode Count: " + sessions.Count); foreach (var session in sessions) { var sessionObj = JObject.Parse(session.ToString()); if (sessionObj == null) { continue; } if (sessionObj["Longitude"] != null && sessionObj["Latitude"] != null) { continue; } var venuePostCode = sessionObj["VenuePostCode"].ToString(); if (string.IsNullOrEmpty(venuePostCode)) { continue; } Console.WriteLine("Attempting to get GetPositionForPostcode"); Position position; Console.WriteLine("Check to see if dictionary contains Position for Postcode"); if (_venuePostcodeDictionary.ContainsKey(venuePostCode)) { position = _venuePostcodeDictionary[venuePostCode]; } else { position = await _azureMapService.GetPositionForAddress(venuePostCode); _venuePostcodeDictionary.Add(venuePostCode, position); } if (sessionObj["Longitude"] == null) { _jsonHelper.CreatePropertyOnJObject(sessionObj, "Longitude", position.Lon); } else { _jsonHelper.UpdatePropertyValue(sessionObj["Longitude"], position.Lon); } if (sessionObj["Latitude"] == null) { _jsonHelper.CreatePropertyOnJObject(sessionObj, "Latitude", position.Lat); } else { _jsonHelper.UpdatePropertyValue(sessionObj["Latitude"], position.Lat); } var sessionId = new Guid(sessionObj["id"].ToString()); Console.WriteLine("SessionId: " + sessionId); Console.WriteLine("Attempting to UpdateSessionAsync"); var updateResponse = await _dbProvider.UpdateSessionAsync(sessionObj.ToString(), sessionId); var responseStatusCode = updateResponse?.StatusCode; if (responseStatusCode == HttpStatusCode.OK) { Console.WriteLine("Successfully Updated: " + sessionId); } else { Console.WriteLine("Unsuccessful geo code update: " + sessionId); } } Console.WriteLine("Finished Bulk Upload"); }