Esempio n. 1
0
        private string GetOriginalUrl(string urlId)
        {
            var originalUrl = "";

            using (var dbContext = new RateSetterDbEntities())
            {
                var link = dbContext.Links.SingleOrDefault(x => x.LinkId == urlId);
                if (link != null)
                {
                    originalUrl = link.OriginalUrl;
                }

                Log logEntry = new Log()
                {
                    RequestType = (short)RequestType.Retrieve,
                    CreateDate  = DateTime.Now,
                    OriginalUrl = originalUrl,
                    ShortUrl    = urlId
                };

                dbContext.Logs.Add(logEntry);
                dbContext.SaveChanges();
            }

            return(originalUrl);
        }
Esempio n. 2
0
        private string ShortenUrl(string url)
        {
            var shortUrl = Utils.Utils.GetNewShortUrl(out string guid);

            using (var dbContext = new RateSetterDbEntities())
            {
                Link link = new Link()
                {
                    LinkId      = guid,
                    OriginalUrl = url,
                    ShortUrl    = shortUrl,
                    CreateDate  = DateTime.Now
                };

                Log logEntry = new Log()
                {
                    RequestType = (short)RequestType.Create,
                    CreateDate  = DateTime.Now,
                    OriginalUrl = url,
                    ShortUrl    = shortUrl
                };

                dbContext.Links.Add(link);
                dbContext.Logs.Add(logEntry);
                dbContext.SaveChanges();
            }

            return(shortUrl);
        }
Esempio n. 3
0
 private List <Link> GetAllLinks()
 {
     using (var dbContext = new RateSetterDbEntities())
     {
         return(dbContext.Links.ToList());
     }
 }