示例#1
0
        public async Task <InventoryItem> PutInventoryItem(InventoryItem item)
        {
            //Grab a link to the collection
            var collection = await DocumentDbUtil.GetOrCreateCollectionAsync(this.dbClient, this.docDb, this.dbSettings.CollectionId);

            //Store the new document
            var result = await this.dbClient.CreateDocumentAsync(collection.SelfLink, item);

            return((InventoryItem)(dynamic)result.Resource);
        }
示例#2
0
        public InventoryRepository(IDocumentClient documentDbClient, DocumentDbSettings documentDbTypeSettings)
        {
            this.dbClient   = documentDbClient;
            this.dbSettings = documentDbTypeSettings;

            var dbTask = DocumentDbUtil.GetOrCreateDatabaseAsync(this.dbClient, this.dbSettings.DatabaseId);

            dbTask.Wait();
            this.docDb = dbTask.Result;
        }
示例#3
0
        public async Task <InventoryItem> PutInventoryItemWithHack(InventoryItem item)
        {
            //Grab a link to the collection
            var collection = await DocumentDbUtil.GetOrCreateCollectionAsync(this.dbClient, this.docDb, this.dbSettings.CollectionId);

            //Apply a Hacky fix - the regular metod loses it's Concrete properties
            //Running it manually through the serializer at this point seems to "fix" it
            ExpandoObject toStore = JsonConvert.DeserializeObject <ExpandoObject>(JsonConvert.SerializeObject(item));

            var result = await this.dbClient.CreateDocumentAsync(collection.SelfLink, toStore);

            return((InventoryItem)(dynamic)result.Resource);
        }