Exemplo n.º 1
0
        public Tuple <String, Int32> Expand(String hash)
        {
            var id = ShortenerMathBits.Decode(hash);

            var info = _db.GetDetailsFromId(id);

            if (!String.IsNullOrEmpty(info.Url))
            {
                _db.IncrementClickCountById(id);
            }

            return(new Tuple <String, Int32>(info.Url, (info.Clicks++)));
        }
Exemplo n.º 2
0
        public String Shorten(String url)
        {
            url = url.StartsWith("http", StringComparison.CurrentCultureIgnoreCase) ? url : String.Format("http://{0}", url);
            url = url.ToLower();

            var existingId = _db.GetIdForUrl(url);
            var id         = 0;

            if (existingId.HasValue)
            {
                id = existingId.Value;
            }
            else
            {
                id = _db.InsertUrl(url);
            }

            return(ShortenerMathBits.Encode(id));
        }