Esempio n. 1
0
        public IActionResult Post([FromBody] ApiDog apiDog) // model binding still works the time
        {
            // via [ApiController] attribute, we automatically get server-side validation based on ModelState
            // from any DataAnnotations, resulting in automatic 400 response.
            var dog = new Dog {
                Name = apiDog.Name
            };
            var newId = dogRepository.Create(dog);

            return(CreatedAtRoute("Get", new { id = newId }, dogRepository.Get(newId)));
        }
Esempio n. 2
0
 public IActionResult Create(Dog dog)
 {
     _repository.Create(dog);
     return(RedirectToAction("Index"));
 }