Example #1
0
 public static string ShortenUrl(this string longUrl)
 {
     var datastore = new UrlStore();
       var shortUrlPath = longUrl.GetHashCode().ToString();
       datastore.SaveUrl(longUrl, shortUrlPath);
       return shortUrlPath;
 }
Example #2
0
        private Negotiator ShortenUrl(UrlStore urlStore)
        {
            string longUrl = Request.Form.url;
            var shortUrl = ShortenUrl(longUrl);
            urlStore.SaveUrl(longUrl, shortUrl);

            return View["shortened_url", new { Request.Headers.Host, ShortUrl = shortUrl }];
        }
Example #3
0
        private Response ShortenUrl(UrlStore urlStore)
        {
            string longUrl  = Request.Form.url;
            var    shortUrl = ShortenUrl(longUrl);

            urlStore.SaveUrl(longUrl, shortUrl);

            return(View["shortened_url", new { Request.Headers.Host, ShortUrl = shortUrl }]);
        }
Example #4
0
        private Negotiator ShortenAndSaveUrl(UrlStore urlStore)
        {
            string longUrl = Request.Form.url;

            if (longUrl == null)
            {
                var newUrl = this.Bind <NewUrl>();
                longUrl = newUrl.Url;
            }

            if (longUrl == null)
            {
                return(Negotiate.WithModel(new { Message = "Url parameter is null" }));
            }

            var shortUrl = ShortenUrl(longUrl);

            if (urlStore.GetUrlFor(shortUrl) == null)
            {
                urlStore.SaveUrl(longUrl, shortUrl);
            }

            return(Negotiate.WithModel(new { ShortUrl = ("http://" + Request.Headers.Host + "/" + shortUrl) }));
        }