Exemplo n.º 1
0
 public void UpdatePhonebookContact(Phonebook contact)
 {
     using (PhonebookContext db = new PhonebookContext())
     {
         // Loop to look for a match based on name
         var found = db.Phonebooks.FirstOrDefault(c => c.Name.ToUpper() == contact.Name.ToUpper());
         if (found == null)
         {
             throw new ArgumentException("No contact found");
         }
         else
         {
             found.Number  = contact.Number;
             found.Address = contact.Address;
             db.SaveChanges();
         }
     }
 }
Exemplo n.º 2
0
 // 3. Report phone numbers and addresses matching a specified name.
 public void FindName(Phonebook contact)
 {
     using (PhonebookContext db = new PhonebookContext())
     {
         var locateName = db.Phonebooks.Where(c => c.Name == contact.Name);
         foreach (Phonebook item in locateName)
         {
             if (locateName == null)
             {
                 Console.WriteLine("No matching contact name in the Phonebook");
             }
             else
             {
                 Console.WriteLine("\nFound Name: " + "\nContact Name: " + item.Name + "\nContact Number: " + item.Number + "\nAddress: " + item.Address);
             }
         }
     }
 }
Exemplo n.º 3
0
 public void DeleteContact(Phonebook contact)
 {
     using (PhonebookContext db = new PhonebookContext())
     {
         try
         {
             var found = db.Phonebooks.FirstOrDefault(c => c.Name.ToUpper() == contact.Name.ToUpper());
             //Loop to look for a match based on name
             if (found != null)
             {
                 db.Phonebooks.Remove(found);
                 Console.WriteLine("Deleting Contact: " + found.Name);
                 db.SaveChanges();
                 //throw new ArgumentException("Contact could not be found");
             }
         }
         catch (ArgumentException e)
         {
             Console.WriteLine(e.ToString());
         }
     }
 }