示例#1
0
        public async Task <ActionResult <Contact> > AddContact([FromBody] Contact contact)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            contact.Id = _repository.AllContacts().Count() + 1;
            _repository.AddContact(contact);

            return(CreatedAtAction(nameof(Get), _repository.AllContacts()));
        }