public async Task <LicensePlateRegistration> GetByTypeAndNumberAsync( string registrationType, string licensePlateNumber) { var table = GetCloudTable(); LicensePlateRegistration result = null; var retrieveOperation = TableOperation.Retrieve <LicensePlateRegistrationEntity>( registrationType, licensePlateNumber); try { var retrievedResult = await table.ExecuteAsync(retrieveOperation); if (retrievedResult.Result != null) { result = LicensePlateRegistrationMapper.ToLicensePlateRegistration( (LicensePlateRegistrationEntity)retrievedResult.Result); } } catch (Exception e) { throw RepositoryExceptionBuilder.CreateExceptionForTableOperation( registrationType, licensePlateNumber, table, retrieveOperation, e); } return(result); }
private async Task CreateDatabaseAndCollection() { var database = new Database { Id = DatabaseId }; var databaseUri = GetDatabaseUri(); try { await _documentClient.CreateDatabaseIfNotExistsAsync(database); var collection = new DocumentCollection { Id = CollectionId }; collection.PartitionKey.Paths.Add("/owner"); collection.IndexingPolicy.Automatic = true; collection.IndexingPolicy.IndexingMode = IndexingMode.Consistent; collection.IndexingPolicy.IncludedPaths.Clear(); await _documentClient.CreateDocumentCollectionIfNotExistsAsync( databaseUri, collection, new RequestOptions { OfferThroughput = 400 }); } catch (Exception e) { throw RepositoryExceptionBuilder.CreateExceptionForCollectionCreation(databaseUri, CollectionId, e); } }
public async Task AddAsync(ParkingGarage parkingGarage) { try { await _documentClient.CreateDocumentAsync(GetDocumentCollectionUri(), parkingGarage, GetRequestOptions()); } catch (Exception e) { throw RepositoryExceptionBuilder.CreateExceptionForDocumentCreation(parkingGarage, e); } }
public async Task RemoveAsync(string parkingGarageId) { var documentUri = UriFactory.CreateDocumentUri(DatabaseId, CollectionId, parkingGarageId); try { await _documentClient.DeleteDocumentAsync(documentUri); } catch (Exception e) { throw RepositoryExceptionBuilder.CreateExceptionForDocumentDelete(documentUri, e); } }
public async Task UpdateAsync(ParkingGarage parkingGarage) { var documentUri = UriFactory.CreateDocumentUri(DatabaseId, CollectionId, parkingGarage.Id); try { await _documentClient.UpsertDocumentAsync(documentUri, parkingGarage, GetRequestOptions()); } catch (Exception e) { throw RepositoryExceptionBuilder.CreateExceptionForDocumentUpdate(documentUri, e); } }
private CloudTable GetCloudTable() { var cloudTable = _cloudTableClient.GetTableReference(TableName); try { cloudTable.CreateIfNotExists(); } catch (Exception e) { throw RepositoryExceptionBuilder.CreateExceptionForTableCreation(cloudTable, e); } return(cloudTable); }
public async Task <ParkingGarage> GetByNameAsync(string name) { ParkingGarage result; try { var parkingGarage = _documentClient.CreateDocumentQuery <ParkingGarage>(GetDocumentCollectionUri()) .Where(parking => parking.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)) .AsEnumerable() .FirstOrDefault(); result = await Task.FromResult(parkingGarage); } catch (Exception e) { throw RepositoryExceptionBuilder.CreateExceptionForDocumentQuery(nameof(name), name, e); } return(result); }