Example #1
0
 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");
     }
 }
Example #2
0
 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");
     }
 }
Example #3
0
 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");
     }
 }