public async Task <ShortUrlResponse> CreateShortUrl(UrlToShorten urlToShorten) { if (!urlToShorten.LongUrl.Contains("https://") || !urlToShorten.LongUrl.Contains("http://")) { if (urlToShorten.LongUrl.StartsWith("www.")) { urlToShorten.LongUrl = $"{Https}{urlToShorten.LongUrl}"; } } var validUri = Uri.IsWellFormedUriString(urlToShorten.LongUrl, UriKind.Absolute); if (validUri == false) { throw new ArgumentException($"The submitted value isn't a valid url: {urlToShorten}"); } var shortId = CreateRandomString(ShortIdLength); var baseUrl = AssembleBaseUrl(); var urlInformation = new UrlInformation { CreationDate = _clock.Now(), Id = shortId, ShortId = shortId, LogUrl = urlToShorten.LongUrl, ShortUrl = $"{baseUrl}/{shortId}" }; var success = await _cosmosDbRepository.CreateShortUrl(urlInformation); if (success) { return new ShortUrlResponse { ShortUrl = urlInformation.ShortUrl } } ; return(null); }