Ejemplo n.º 1
0
        public static async Task <Models.ShortLink> GetHashIDItemAsync(string hashID)
        {
            if (String.IsNullOrEmpty(hashID) || String.IsNullOrWhiteSpace(hashID))
            {
                return(null);
            }
            Database  database        = cosmosClient.GetDatabase(databaseId);
            Container hashIDContainer = database.GetContainer(hashIDContainerID);
            int       seedValue       = HashIDGenerator.DecodeSeedValue(hashID);

            Models.ShortLink shortLinkResponse;
            try
            {
                shortLinkResponse =
                    await hashIDContainer.ReadItemAsync <Models.ShortLink>(seedValue.ToString(), new PartitionKey(seedValue.ToString()));
            }
            catch (CosmosException ex) when(ex.StatusCode == HttpStatusCode.NotFound)
            {
                shortLinkResponse = null;
            }
            return(shortLinkResponse);
        }