public async Task <StorageRecord> CreateAsync(StorageRecord input) { await this.SetupStorageAsync(); try { var record = input.GetDocumentDbRecord(); record.Touch(); var response = await this.docDb.CreateAsync(this.client, this.storageConfig, record); return(StorageRecord.FromDocumentDb(response?.Resource)); } catch (DocumentClientException e) when(e.StatusCode == HttpStatusCode.Conflict) { this.log.Info("There is already a resource with the id specified.", () => new { this.storageName, input.Id }); throw new ConflictingResourceException($"There is already a resource with id = '{input.Id}'."); } }
public async Task <StorageRecord> UpsertAsync(StorageRecord input, string eTag) { await this.SetupStorageAsync(); try { var record = input.GetDocumentDbRecord(); record.Touch(); var response = await this.docDb.UpsertAsync(this.client, this.storageConfig, record, eTag); return(StorageRecord.FromDocumentDb(response?.Resource)); } catch (DocumentClientException e) when(e.StatusCode == HttpStatusCode.PreconditionFailed) { this.log.Info( "E-Tag mismatch: the resource has been updated by another client.", () => new { this.storageName, input.Id, input.ETag }); throw new ConflictingResourceException("E-Tag mismatch: the resource has been updated by another client."); } }