Пример #1
0
 public IActionResult SaveChanges(UrlRecord url)
 {
     if (url.Short == null)
     {
         url.Short      = String.Join("", Guid.NewGuid().ToString().Replace("-", "").Take(5));
         url.CreateTime = DateTime.Now;
         while (true)
         {
             try
             {
                 entity.Urls.Add(url);
                 entity.SaveChanges();
                 break;
             }
             catch (Exception)
             {
                 url.Short = String.Join("", Guid.NewGuid().ToString().Replace("-", "").Take(5));
                 continue;
             }
         }
     }
     else
     {
         try
         {
             var u = entity.Urls.Single(x => x.Short == url.Short);
             u.UrlData  = url.UrlData;
             u.IsEnable = url.IsEnable;
             entity.SaveChanges();
         }
         catch (Exception ex)
         {
             return(Content("<script>alert('Your information insufficient.');location.href='" + Url.Action("Edit", "Admin", new { Id = url.Short }) + "'</script>"));
         }
     }
     return(new RedirectResult(Url.Action("Index", "Admin", new { })));
 }
Пример #2
0
 public IActionResult Index(string go)
 {
     try
     {
         var UrlRecord = entity.Urls.Single(x => x.Short == go);
         if (!UrlRecord.IsEnable)
         {
             return(Content(""));
         }
         UrlRecord.Counter++;
         entity.SaveChanges();
         return(new RedirectResult(UrlRecord.UrlData));
     }
     catch (Exception ex)
     {
         return(Content(""));
     }
 }