Esempio n. 1
0
        public IActionResult CreateAuthor([FromHeader] string AuthorizedCode, [FromBody] AuthorInputModel body)
        {
            if (AuthorizedCode == null || AuthorizedCode != _password)
            {
                return(StatusCode(403));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest("input model not valid"));
            }
            var news = _newsService.CreateAuthor(body);

            return(CreatedAtRoute("GetAuthorById", new { id = news.Id }, null));
        }
Esempio n. 2
0
        public IActionResult CreateAuthor(AuthorInputModel newAuthor)
        {
            string authHeader = Request.Headers["Authorization"];

            if (secretKey != authHeader)
            {
                return(Unauthorized());
            }
            ;
            if (!ModelState.IsValid)
            {
                return(StatusCode(412, newAuthor));
            }

            var id = _newsService.CreateAuthor(newAuthor);

            return(CreatedAtRoute("GetAuthorById", new { id }, null));
        }