public async Task <Travel> Get(TravelId id) { try { ItemResponse <TravelDal> response = await this._container.ReadItemAsync <TravelDal>(id.ToString(), new PartitionKey(id.ToString())); var travelDal = response.Resource; return(TravelModelMapper.FromDalModel(travelDal)); } catch (CosmosException ex) when(ex.StatusCode == System.Net.HttpStatusCode.NotFound) { return(null); } }
public async Task <IReadOnlyCollection <Travel> > Get() { var query = this._container.GetItemQueryIterator <TravelDal>(); List <TravelDal> results = new List <TravelDal>(); while (query.HasMoreResults) { var response = await query.ReadNextAsync(); results.AddRange(response.ToList()); } List <Travel> travels = new List <Travel>(); foreach (var travelDal in results) { travels.Add(TravelModelMapper.FromDalModel(travelDal)); } return(travels); }
public async Task Update(Travel travel) { var travelDal = TravelModelMapper.FromDomainModel(travel); await this._container.UpsertItemAsync <TravelDal>(travelDal, new PartitionKey(travelDal.Id.ToString())); }