public ShortUrl(ShortenUrlFunctions.ShortenUrlDelegate shortenUrl, string originalUrl)
 {
     this.OriginalUrl  = originalUrl;
     this.ShortnedUrl  = shortenUrl(originalUrl);
     this.RowKey       = this.ShortnedUrl;
     this.PartitionKey = "ShortUrl";
     this.HitCount     = 0;
 }
        public ShortUrlResponse(
            ShortenUrlFunctions.SaveShortUrlDelegate saveShortUrl,
            ShortenUrlFunctions.ShortenUrlDelegate shortenUrl,
            ShortenUrlFunctions.RetrieveShortUrlDelegate retrieveShortUrl,
            ShortUrlRequest request)
        {
            var responseObject = new ShortUrlResponseObject();

            this.value = responseObject;
            responseObject.OriginalUrl = request.OriginalUrl;

            Uri originalUrl;

            if (Uri.TryCreate(request.OriginalUrl, UriKind.Absolute, out originalUrl) &&
                this.validUrlScheme.Any((scheme) => originalUrl.Scheme == scheme))
            {
                this.StatusCode = HttpStatusCode.OK;
                var shortUrl         = new ShortUrl(shortenUrl, originalUrl.AbsoluteUri);
                var existingShortUrl = retrieveShortUrl(shortUrl.ShortnedUrl)
                                       .Result;
                if (existingShortUrl == null)
                {
                    saveShortUrl(shortUrl);
                }
                responseObject.ShortUrl = shortUrl.ShortnedUrl;
            }
            else
            {
                this.StatusCode       = HttpStatusCode.BadRequest;
                responseObject.Errors = new Dictionary <string, string>
                {
                    {
                        "originalUrl", "The OriginalUrl field is not a valid fully-qualified http, https, or ftp URL."
                    }
                };
            }
        }