public static async Task <Models.ShortLink> CreateHashIDItemIfNotExistsAsync(string url) { if (String.IsNullOrEmpty(url) || String.IsNullOrWhiteSpace(url)) { throw new ArgumentException("Input URL cannot be null, empty or whitespaces"); } Database database = cosmosClient.GetDatabase(databaseId); Container hashIDContainer = database.GetContainer(hashIDContainerID); int currentSeedValue = await SeedValueDBRepository.GetCurrentSeedValueAsync(); string hashID = HashIDGenerator.EncodeSeedValue(currentSeedValue); Models.ShortLink shortLinkResponse = hashIDContainer.GetItemLinqQueryable <Models.ShortLink>(true) .Where(shortLink => shortLink.Url == url) .AsEnumerable() .FirstOrDefault(); if (shortLinkResponse == null) { Models.ShortLink newShortlink = new Models.ShortLink { Id = currentSeedValue.ToString(), Url = url, HashID = hashID, CreatedTime = DateTime.UtcNow, }; shortLinkResponse = await hashIDContainer.CreateItemAsync(newShortlink, new PartitionKey(newShortlink.Id)); currentSeedValue = await SeedValueDBRepository.GetCurrentSeedValueAsync(); SeedValueDBRepository.UpdateSeedValueItemAsync(currentSeedValue + 1); } return(shortLinkResponse); }