Beispiel #1
0
 private void btnImportUrlShortenersList_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     using (var client = new WebClient()) {
         var dataString = client.DownloadString("https://kosciol-jezusa.pl/api/UrlShortList");
         if (dataString.IsNotNullOrEmpty())
         {
             var result = JsonConvert.DeserializeObject <List <UrlShortInfo> >(dataString);
             if (result.IsNotNull())
             {
                 var uow = new UnitOfWork();
                 foreach (var item in result)
                 {
                     var q = new XPQuery <UrlShort>(uow).Where(x => x.ShortUrl == item.Short).Any();
                     if (!q)
                     {
                         var s = new UrlShort(uow)
                         {
                             ShortUrl = item.Short,
                             Url      = item.Url
                         };
                         s.Save();
                         uow.CommitChanges();
                     }
                 }
             }
         }
     }
 }
Beispiel #2
0
        public ActionResult <string> Get()
        {
            var url        = GetReqParam("url");
            var host       = this.Request.Host.ToString();
            var hostPrefix = Request.IsHttps ? "https://" : "http://";

            if (url.IsNotNullOrEmpty())
            {
                var uow  = new UnitOfWork();
                var _url = new XPQuery <UrlShort>(uow).Where(x => x.Url == url).FirstOrDefault();
                if (_url.IsNull())
                {
                    _url = new UrlShort(uow)
                    {
                        Url      = url,
                        ShortUrl = GetShortUrl(uow)
                    };
                    _url.Save();
                    uow.CommitChanges();
                }

                return($"{hostPrefix}{host}/{_url.ShortUrl}");
            }
            return(url);
        }