public ObjectResult Create([FromBody] ContactViewModel contact) { CheckModel(contact); if (ModelState.IsValid) { var id = Guid.NewGuid(); var entity = GetContact(contact, id); ContactsRepository.Create(entity); return(StatusCode((int)HttpStatusCode.Created, id.ToString())); } return(BadRequest(ModelState)); }
public IActionResult Post([FromBody] ContactViewModel contact) { try { if (ModelState.IsValid) { var repoContacts = new ContactsRepository(_context); var createdContact = repoContacts.Create(contact); return(Created("newContact", createdContact)); } return(BadRequest(ModelState)); } catch (Exception e) { throw new Exception(e.Message); } }
public void Create([FromBody] Contact contact) { _contactsRepository.Create(contact); }