public async Task <(HttpStatusCode, ShortUrl)> UpsertShortUrlAsync(ShortUrl shortUrl) { Guard.ArgumentNotNull(nameof(shortUrl), shortUrl); Guard.ArgumentNotNullOrEmpty(nameof(shortUrl.LongUrl), shortUrl.LongUrl); Guard.ArgumentNotNull(nameof(shortUrl.Expiration), shortUrl.Expiration); shortUrl.Id = _urlShortenerAlgorithm.GenerateUniqueId(); _database.Add(shortUrl.Id, shortUrl); return(HttpStatusCode.OK, shortUrl); }
public async Task <(HttpStatusCode, ShortUrl)> UpsertShortUrlAsync(ShortUrl shortUrl) { Guard.ArgumentNotNull(nameof(shortUrl), shortUrl); Guard.ArgumentNotNullOrEmpty(nameof(shortUrl.LongUrl), shortUrl.LongUrl); Guard.ArgumentNotNull(nameof(shortUrl.Expiration), shortUrl.Expiration); if (string.IsNullOrWhiteSpace(shortUrl.Id)) { shortUrl.Id = _urlShortenerAlgorithm.GenerateUniqueId(); } var document = CreateDocument(shortUrl.ToShortUrlCosmosDocument()); // var document = new ShortUrlCosmosDocument(shortUrl.ToShortUrlCosmosDocument()); var response = await _simpleItemDbContext.UpsertItemAsync(document); return(response.StatusCode, shortUrl); }