public async Task <TripItem> UpsertTrip(TripItem trip, bool isIgnoreChangeFeed = false) { var error = ""; double cost = 0; try { if (string.IsNullOrEmpty(_docDbDigitalMainCollectionName)) { throw new Exception("No Digital Main collection defined!"); } // Just making sure... trip.CollectionType = ItemCollectionTypes.Trip; trip.UpsertDate = DateTime.Now; bool blInsert = false; if (trip.Id == "") { trip.Code = Utilities.GenerateRandomAlphaNumeric(8); trip.Id = $"{trip.Code}-{trip.CollectionType}"; blInsert = true; } if (trip.EndDate != null) { trip.Duration = ((DateTime)trip.EndDate - trip.StartDate).TotalSeconds; } var response = await(await GetDocDBClient(_settingService)).UpsertDocumentAsync(UriFactory.CreateDocumentCollectionUri(_docDbDatabaseName, _docDbDigitalMainCollectionName), trip); cost = response.RequestCharge; if (!isIgnoreChangeFeed && blInsert) { await _changeNotifierService.TripCreated(trip, await RetrieveActiveTripsCount()); } } catch (Exception ex) { error = ex.Message; throw new Exception(error); } finally { _loggerService.Log($"{LOG_TAG} - UpsertTrip - Error: {error}"); } return(trip); }
public async Task <TripItem> UpsertTrip(TripItem trip, bool isIgnoreChangeFeed = false) { var error = ""; try { if (string.IsNullOrEmpty(_docDbDigitalMainCollectionName)) { throw new Exception("No Digital Main collection defined!"); } // Just making sure... trip.CollectionType = ItemCollectionTypes.Trip; trip.UpsertDate = DateTime.Now; bool blInsert = false; if (trip.Id == "") { trip.Code = Utilities.GenerateRandomAlphaNumeric(8); trip.Id = $"{trip.Code}-{trip.CollectionType}"; blInsert = true; } if (trip.EndDate != null) { trip.Duration = ((DateTime)trip.EndDate - trip.StartDate).TotalSeconds; } var response = await(await GetCosmosContainer()).UpsertItemAsync(trip, new PartitionKey(trip.Code.ToUpper())); if (!isIgnoreChangeFeed && blInsert) { await _changeNotifierService.TripCreated(trip, await RetrieveActiveTripsCount()); } return(response.Resource); } catch (Exception ex) { error = ex.Message; throw new Exception(ex.Message, ex); } finally { _loggerService.Log($"{LOG_TAG} - UpsertTrip - Error: {error}"); } }