public IHttpActionResult PostEHContact(EHContact eHContact) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.EHContacts.Add(eHContact); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = eHContact.ContactID }, eHContact)); }
public IHttpActionResult GetEHContact(int id) { EHContact eHContact = db.EHContacts.Find(id); if (eHContact == null) { return(NotFound()); } return(Ok(eHContact)); }
public IHttpActionResult DeleteEHContact(int id) { EHContact eHContact = db.EHContacts.Find(id); if (eHContact == null) { return(NotFound()); } db.EHContacts.Remove(eHContact); db.SaveChanges(); return(Ok(eHContact)); }
public IHttpActionResult PutEHContact(EHContact eHContact) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var existingContact = db.EHContacts.Where(s => s.ContactID == eHContact.ContactID) .FirstOrDefault <EHContact>(); if (existingContact != null) { existingContact.FirstName = eHContact.FirstName; existingContact.LastName = eHContact.LastName; existingContact.Email = eHContact.Email; existingContact.PhoneNumber = eHContact.PhoneNumber; existingContact.Status = eHContact.Status; db.SaveChanges(); } else { return(NotFound()); } return(Ok(eHContact)); }