//upplägg till nya foton för verifiering private async Task AddNewPhotosToVerify(string databaseName, string collectionName, string inputPhotoUrl) { await this.client.CreateDatabaseIfNotExistsAsync(new Database { Id = databaseName }); await this.client.CreateDocumentCollectionIfNotExistsAsync(UriFactory.CreateDatabaseUri(databaseName), new DocumentCollection { Id = collectionName }); VerifyPhotosCollection ver = new VerifyPhotosCollection(); { //slumpgenererad kod för ver.id-värde!! string randomSequence = GetRandomAlphaNumeric(); ver.Id = randomSequence; //ver.VerId = "4"; framtida feature: hämta högsta id från db och plussa på ett!! //ver.UserId = inputUserID; framtida feature: hämta högsta id från db och plussa på ett!! ver.PhotoUrl = inputPhotoUrl; } await this.CreateVerifyDocumentIfNotExists(databaseName, collectionName, ver); }
//skapande av foton-som-skall-verifieras-dokument i cosmos ;) public async Task CreateVerifyDocumentIfNotExists(string databaseName, string collectionName, VerifyPhotosCollection ver) { try { await this.client.ReadDocumentAsync(UriFactory.CreateDocumentUri(databaseName, collectionName, ver.Id)); //this.WriteToConsoleAndPromptToContinue("Found {0}", users.Id); } catch (DocumentClientException de) { if (de.StatusCode == HttpStatusCode.NotFound) { await this.client.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(databaseName, collectionName), ver); //this.WriteToConsoleAndPromptToContinue("Created Family {0}", users.Id); } else { throw; } } }