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")); }
public PartialViewResult _GenerateUrl(UrlGeneratorViewModel model) { ShortUrlContainer oShortUrl = new ShortUrlContainer(); ShortUrlUtils utils = new ShortUrlUtils(); oShortUrl.Title = model.Title; oShortUrl.Description = model.Description; oShortUrl.RealUrl = model.Link; oShortUrl.Image = model.Image; oShortUrl.ShortenedUrl = utils.UniqueShortUrl(); oShortUrl.CreateDate = DateTime.Now; oShortUrl.CreatedBy = Request.UserHostAddress; //utils.AddUrlToDatabase(oShortUrl); oShortUrl.ShortenedUrl = utils.PublicShortUrl(oShortUrl.ShortenedUrl); var generatedUrl = new GeneratedUrlViewModel(); generatedUrl.Link = oShortUrl.ShortenedUrl; return(PartialView("_GeneratedUrlResult", generatedUrl)); }