public ActionResult Create(Link link)
 {
     ViewBag.Title = "Create a single-use link.";
     ViewBag.Message = "The link you create here will only serve once.  This is useful to limit the sharing of content.";
     ModelState.Remove("ShortUrl");
     try
     {
         if (ModelState.IsValid)
         {
             string shortLink = Guid.NewGuid().ToString().Substring(0, 6);
             //TODO - This may not scale
             while (database.Links.Count(a => a.ShortUrl.Equals(shortLink, StringComparison.OrdinalIgnoreCase)) > 0)
             {
                 shortLink = Guid.NewGuid().ToString().Substring(0, 6);
             }
             link.ShortUrl = shortLink;
             database.Links.Add(link);
             database.SaveChanges();
             return RedirectToAction("Success", new { Id = link.ShortUrl });
         }
         else
         {
             return View(link);
         }
     }
     catch (Exception e)
     {
         ViewBag.Error = e.GetBaseException().Message;
         return View(link);
     }
 }
 //
 // GET: /Links/Create
 public ActionResult Create()
 {
     ViewBag.Title = "Create a single-use link.";
     ViewBag.Message = "The link you create here will only serve once.  This is useful to limit the sharing of content.";
     Link newLink = new Link();
     return View(newLink);
 }
 private void SendNotification(Link link)
 {
     if (!string.IsNullOrWhiteSpace(link.OptionalEmailAddress))
     {
         EmailHelper.SendEmailAsync("LinkOnce Notifier <*****@*****.**>",
             link.OptionalEmailAddress,
             "Your link has been used",
             "<html><body><h3>Your link has been used</h3><p>The link to " + link.Destination + " was retrieved " + link.DateUsed.ToLongDateString() +
             " at " + link.DateUsed.ToLongTimeString() + "</p>" +
             "<p>This link is no longer usable</p>" +
             "<p class='footer'>You are receiving this message because you opted to be notified when this link was used.</p>" +
             "</body></html>", true);
     }
 }
 private void PrepareHeaders(Link link, WebResponse resp)
 {
     Response.ContentType = resp.ContentType;
     foreach (var h in resp.Headers.AllKeys)
     {
         Response.Headers.Add(h, resp.Headers[h]);
     }
     if (Response.Headers["Content-Disposition"] == null)
     {
         Response.Headers.Add("Content-Disposition", "attachment; filename=" + Path.GetFileName(link.Destination));
     }
 }