示例#1
0
 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));
 }
示例#2
0
        public IHttpActionResult GetEHContact(int id)
        {
            EHContact eHContact = db.EHContacts.Find(id);

            if (eHContact == null)
            {
                return(NotFound());
            }
            return(Ok(eHContact));
        }
示例#3
0
        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));
        }
示例#4
0
        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));
        }