public IHttpActionResult DeleteProduct(int id) { try { if (id <= 0) { return(BadRequest("Not a valid contact id")); } using (var ctx = new MYCONTACTBOOKEntities()) { var contact = ctx.Contacts .Where(c => c.ContactID == id) .FirstOrDefault(); ctx.Entry(contact).State = System.Data.Entity.EntityState.Deleted; ctx.SaveChanges(); } } catch (Exception) { return(BadRequest("Not a valid contact id")); } return(Ok()); }
public IHttpActionResult PostNewContact(Contact c) { try { if (!ModelState.IsValid) { return(BadRequest("Not a valid model")); } using (var ctx = new MYCONTACTBOOKEntities()) { ctx.Contacts.Add(new Contact() { ContactPersonFname = c.ContactPersonFname, ContactPersonLname = c.ContactPersonLname, ContactNo1 = c.ContactNo1, ContactNo2 = c.ContactNo1, EmailID = c.EmailID, CountryID = c.CountryID, StateID = c.StateID, Address = c.Address, ImagePath = c.ImagePath }); ctx.SaveChanges(); } } catch (Exception ex) { return(BadRequest("Not a valid model")); } return(Ok()); }