Пример #1
0
        public ActionResult Index(string url)
        {
            //create the record
            var oUrl = new WutLink
            {
                RealUrl     = url,
                CreateDate  = DateTime.UtcNow,
                CreatedByIp = Request.UserHostAddress
            };

            //tag it if logged in, for posterity or cool reporting later
            if (User.Identity.IsAuthenticated)
            {
                oUrl.UserId = User.Identity.GetClaim <int>(CustomClaimTypes.UserId);
            }

            //save it
            oUrl = ShortUrlUtils.AddUrlToDatabase(oUrl, Wutcontext);

            //set it up to display
            ViewBag.ShortUrl    = ShortUrlUtils.PublicShortUrl(oUrl.ShortUrl);
            ViewBag.NavigateUrl = oUrl.RealUrl;

            //go back home
            return(View("~/Views/Home/Index.cshtml"));
        }
Пример #2
0
        public static WutLink AddUrlToDatabase(WutLink oUrl, WutNuContext models)
        {
            oUrl.ShortUrl = UniqueShortUrl(models);

            models.WutLinks.Add(oUrl);
            models.SaveChanges();
            return(oUrl);
        }