Exemplo n.º 1
0
        public async Task <IActionResult> Get(string slug)
        {
            var shortenedUrl = await _urlProvider.GetUrl(slug);

            if (shortenedUrl == null)
            {
                return(NotFound());
            }

            return(Json(shortenedUrl));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Go()
        {
            string slug = Request.Path;

            var shortenedUrl = await _urlProvider.GetUrl(slug.TrimStart('/'));

            if (shortenedUrl == null)
            {
                return(NotFound());
            }

            if (shortenedUrl.IsExpired)
            {
                return(Content("We are sorry, the link has expired :("));
            }

            return(await Task.Run <ActionResult>(() =>
            {
                return Redirect(shortenedUrl.Url);
            }));
        }