Example #1
0
 public bool HashInUse(string hash)
 {
     using (var context = new UrlContext(_connectionString))
     {
         return(context.Urls.Any(h => hash == h.Hash));
     }
 }
Example #2
0
 public Url GetOriginalUrl(string hash)
 {
     using (var context = new UrlContext(_connectionString))
     {
         return(context.Urls.FirstOrDefault(h => h.Hash == hash));
     }
 }
Example #3
0
        public string AddUrl(string url)
        {
            Url u = new Url();

            u.OriginalUrl = url;
            u.Hash        = ShortId.Generate(10);
            while (HashInUse(u.Hash))
            {
                u.Hash = ShortId.Generate(10);
            }

            using (var context = new UrlContext(_connectionString))
            {
                context.Urls.Add(u);
                context.SaveChanges();
            }

            return(u.Hash);
        }