public string InsertContact(Contact contact) { if (contact != null) { using (StudyDBEntities Obj = new StudyDBEntities()) { Obj.Contacts.Add(contact); Obj.SaveChanges(); return("Contact Added Successfully"); } } else { return("Contact Not Inserted! Try Again"); } }
public string DeleteContact(Contact contact) { if (contact != null) { using (StudyDBEntities Obj = new StudyDBEntities()) { var Contact_ = Obj.Entry(contact); if (Contact_.State == EntityState.Detached) { Obj.Contacts.Attach(contact); Obj.Contacts.Remove(contact); } Obj.SaveChanges(); return("Contact Deleted Successfully"); } } else { return("Contact Not Deleted! Try Again"); } }
public string UpdateContact(Contact contact) { if (contact != null) { using (StudyDBEntities Obj = new StudyDBEntities()) { var Contact_ = Obj.Entry(contact); Contact contact_ = Obj.Contacts.Where(x => x.ID == contact.ID).FirstOrDefault(); contact_.FirstName = contact.FirstName; contact_.LastName = contact.LastName; contact_.Email = contact.Email; contact_.PhoneNumber = contact.PhoneNumber; Obj.SaveChanges(); return("Contact Updated Successfully"); } } else { return("Contact Not Updated! Try Again"); } }