예제 #1
0
 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);
     }
 }
예제 #3
0
 public void Create([FromBody] Contact contact)
 {
     _contactsRepository.Create(contact);
 }