Beispiel #1
0
        public ShortUrlContainer RetrieveUrlFromDatabase(string internal_url)
        {
            ShortUrlContainer oShortUrl = new ShortUrlContainer();

            oShortUrl.ShortenedUrl = internal_url;

            using (var _db = new UrlsDBContext())
            {
                try
                {
                    var clean_url = this.Clean(internal_url);

                    var url = (from c in _db.Urls where c.ShortenedUrl == clean_url select c).FirstOrDefault();
                    if (url != null)
                    {
                        oShortUrl.CreateDate  = url.CreateDate;
                        oShortUrl.CreatedBy   = url.CreatedBy;
                        oShortUrl.RealUrl     = url.RealUrl;
                        oShortUrl.Title       = url.Title;
                        oShortUrl.Description = url.Description;
                        oShortUrl.Image       = url.Image;
                    }
                }
                catch (Exception exp)
                {
                    throw new Exception("ERROR: Unable to Retrieve ShortUrlContainer - " + exp.Message.ToString(), exp);
                }
            }

            return(oShortUrl);
        }
Beispiel #2
0
 public void AddUrlToDatabase(ShortUrlContainer oShortUrl)
 {
     using (UrlsDBContext _db = new UrlsDBContext())
     {
         // Add product to DB.
         _db.Urls.Add(oShortUrl);
         _db.SaveChanges();
     }
 }
Beispiel #3
0
        public string UniqueShortUrl()
        {
            string short_url = RandomCharacters();

            using (var _db = new UrlsDBContext())
            {
                try
                {
                    var url = (from c in _db.Urls where c.ShortenedUrl == short_url select c).FirstOrDefault();
                    if (url != null)
                    {
                        short_url = RandomCharacters();
                    }
                }
                catch (Exception exp)
                {
                    throw new Exception("ERROR: Unable to Retrieve ShortUrlContainer - " + exp.Message.ToString(), exp);
                }
            }

            return(short_url);
        }