예제 #1
0
        public async Task <IActionResult> Get()
        {
            var cosmosCollection = new CosmosCollection <User>("UsersCollection");
            var items            = await cosmosCollection.GetItemsAsync();

            return(Ok(items.AsQueryable()));
        }
예제 #2
0
        public async Task <IActionResult> Get(string key)
        {
            // Get the version stamp of the entity
            string entityTag = string.Empty;

            if (Request.Headers.ContainsKey("If-None-Match"))
            {
                entityTag = Request.Headers["If-None-Match"].First();
            }

            var cosmosCollection = new CosmosCollection <Auction>("AuctionsCollection");
            var resultantSet     = await cosmosCollection.GetItemsAsync(item => item.Id == key);

            var auction = resultantSet.FirstOrDefault();

            if (auction == null)
            {
                return(NotFound());
            }

            if (int.TryParse(entityTag, out int timeStamp) && auction.TimeStamp == timeStamp)
            {
                return(StatusCode((int)HttpStatusCode.NotModified));
            }

            return(Ok(auction));
        }
        public IActionResult Get()
        {
            var cosmosCollection = new CosmosCollection <Auction>("AuctionsCollection");
            var items            = cosmosCollection.GetItemsAsync();

            return(Ok(items.AsQueryable()));
        }
예제 #4
0
        public async Task <IActionResult> Patch(string key, [FromBody] JsonPatchDocument <Auction> auctionPatch)
        {
            var cosmosCollection = new CosmosCollection <Auction>("AuctionsCollection");
            var auction          = (await cosmosCollection.GetItemsAsync(item => item.Id == key)).FirstOrDefault();

            if (auction == null)
            {
                return(NotFound());
            }

            auctionPatch.ApplyTo(auction);

            await cosmosCollection.UpdateItemAsync(key, auction);

            return(Accepted(auction));
        }
예제 #5
0
        public async Task <IActionResult> Put([FromODataUri] string key, [FromBody] Auction auctionUpdate)
        {
            var cosmosCollection = new CosmosCollection <Auction>("AuctionsCollection");
            var auction          = (await cosmosCollection.GetItemsAsync(item => item.Id == key)).FirstOrDefault();

            if (auction == null)
            {
                return(NotFound());
            }

            if (auction.TimeStamp != auctionUpdate.TimeStamp)
            {
                return(Conflict());
            }

            await cosmosCollection.UpdateItemAsync(key, auctionUpdate);

            return(Accepted(auction));
        }