Exemplo n.º 1
0
        public IActionResult RedirectLink(string hash)
        {
            Link linkToRedirect = _repository.GetLinkByHash(hash);

            if (!(Request.Cookies[hash] is null))
            {
                return(Redirect(linkToRedirect.OriginalLink));
            }

            linkToRedirect.Visitors += 1;
            _repository.Update(linkToRedirect);

            AddCookie(hash);

            return(Redirect(linkToRedirect.OriginalLink));
        }
Exemplo n.º 2
0
        public IActionResult Update([FromBody] LinkUpdate update)
        {
            if (!(update.Link.IsValidHttpLink() || update.Link.IsValidHttpsLink()))
            {
                return(BadRequest(new { message = "Not valid link" }));
            }


            Link linkInformation = _repository.GetLinkByHash(update.Hash);

            if (linkInformation == null)
            {
                return(BadRequest(new { message = "Link does not exists" }));
            }

            linkInformation.OriginalLink = update.Link;
            _repository.Update(linkInformation);

            return(Ok(new { message = "Updated" }));
        }