Beispiel #1
0
        public ActionResult <Snippet> UpdateSnippet(UpdateSnippetRequest updateSnippetRequest, [FromHeader] string Authorization)
        {
            string tokenString = Authorization.Split(' ')[1];
            var    handler     = new JwtSecurityTokenHandler();
            var    token       = handler.ReadJwtToken(tokenString) as JwtSecurityToken;
            var    email       = token.Claims.First(claim => claim.Type == ClaimTypes.Email).Value;

            if (_snippetService.GetSnippetByHash(updateSnippetRequest.Hash).CreatorEmail == email)
            {
                if (!_snippetService.UpdateSnippet(updateSnippetRequest.Hash, updateSnippetRequest))
                {
                    return(NotFound(updateSnippetRequest.Hash));
                }
            }
            return(Ok(updateSnippetRequest));
        }