Exemple #1
0
        public IActionResult Post([FromBody] Hero value)
        {
            var hero = service.SaveHero(value);

            if (hero != null)
            {
                return(Created("api/hero" + hero.Id, hero));
            }
            return(BadRequest("Rip there is no hero here!"));
        }
        public IActionResult Put(Hero hero)
        {
            _logger.LogInformation(hero.ToString());

            // Is there a hero with the given ID?
            bool exists = _heroService.ExistsHero(hero.ID);

            if (!exists)
            {
                // HTTP status code: 404 (Not Found)
                return(NotFound(hero));
            }

            // Update the hero.
            _heroService.SaveHero(hero);

            // REST API recommends either a status code of 200 (OK) or 204 (No Content) to be returned.
            // HTTP status code: 200 (OK)
            //return Ok(hero);
            // HTTP status code: 204 (No Content)
            return(NoContent());
        }