Esempio n. 1
0
 public IEnumerable <Contact> Get_AllContacts()
 {
     using (StudyDBEntities Obj = new StudyDBEntities())
     {
         List <Contact> Emp = Obj.Contacts.ToList();
         return(Emp);
     }
 }
Esempio n. 2
0
 public Contact GetContactById(string Id)
 {
     using (StudyDBEntities Obj = new StudyDBEntities())
     {
         int ContactId = int.Parse(Id);
         return(Obj.Contacts.Find(ContactId));
     }
 }
Esempio n. 3
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");
     }
 }
Esempio n. 4
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");
     }
 }
Esempio n. 5
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");
     }
 }