Esempio n. 1
0
        public async Task <IActionResult> WithToken(string token)
        {
            if (string.IsNullOrWhiteSpace(token))
            {
                return(this.RedirectToAction(nameof(Index)));
            }

            var fullUrl = await _urlStore.Fetch(token);

            if (string.IsNullOrWhiteSpace(fullUrl))
            {
                return(this.RedirectToAction(nameof(LinkNotFound)));
            }

            return(this.Redirect(fullUrl));
        }
Esempio n. 2
0
        public async Task <IActionResult> Get(string token)
        {
            if (string.IsNullOrWhiteSpace(token))
            {
                return(this.BadRequest("a url to shorten is required."));
            }

            var fullUrl = await _urlStore.Fetch(token);

            if (string.IsNullOrWhiteSpace(fullUrl))
            {
                return(this.NotFound("No url registered for that token"));
            }

            var responseModel = new FetchUrlResponse
            {
                FullUrl = fullUrl,
                Token   = token
            };

            return(this.Ok(responseModel));
        }