Example #1
0
        public bool UpdateSnippet(string hash, UpdateSnippetRequest updateSnippetRequest)
        {
            Snippet snippet = _snippetRepository.GetSnippetByHash(hash);

            if (snippet != null)
            {
                snippet.Content      = updateSnippetRequest.NewContent;
                snippet.LastModified = _dateTime.Now.ToString("g");
                _snippetRepository.UpdateSnippet(snippet);
                return(true);
            }

            return(false);
        }
Example #2
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));
        }