Contact Remove(ContactStore store, Contact c)
        {
            Contact removed;

            store.Remove(c, out removed);

            return(removed);
        }
        public void RemoveWithFilter()
        {
            ContactStore store      = new ContactStore();
            Contact      c1_with_id = store.Add(Contact.Create("fn1", "ln1", "street1", "city1", "st1", "zip1"));
            Contact      c2_with_id = store.Add(Contact.Create("fn2", "ln2", "street2", "city2", "st2", "zip2"));
            Contact      c3_with_id = store.Add(Contact.Create("fn3", "ln3", "street3", "city3", "st3", "zip3"));
            Contact      c4_with_id = store.Add(Contact.Create("fn4", "ln4", "street4", "city4", "st4", "zip4"));
            Contact      c5_with_id = store.Add(Contact.Create("fn5", "ln5", "street5", "city5", "st5", "zip5"));
            Contact      c6_with_id = store.Add(Contact.Create("fn6", "ln6", "street6", "city6", "st6", "zip6"));
            Contact      c7_with_id = store.Add(Contact.Create("fn7", "ln7", "street7", "city7", "st7", "zip7"));

            Assert.AreEqual(7, store.Contacts.Count());

            Contact removed;

            ContactFieldFilter filterFN = new ContactFieldFilter();

            filterFN.SetFirstName("fn1");
            Assert.IsTrue(store.Remove(filterFN, out removed));
            Assert.AreEqual(1, removed.ID.Value);

            ContactFieldFilter filterLN = new ContactFieldFilter();

            filterLN.SetLastName("ln2");
            Assert.IsTrue(store.Remove(filterLN, out removed));
            Assert.AreEqual(2, removed.ID.Value);

            ContactFieldFilter filterStreet = new ContactFieldFilter();

            filterStreet.SetStreetAddress("street3");
            Assert.IsTrue(store.Remove(filterStreet, out removed));
            Assert.AreEqual(3, removed.ID.Value);

            ContactFieldFilter filterCity = new ContactFieldFilter();

            filterCity.SetCity("city4");
            Assert.IsTrue(store.Remove(filterCity, out removed));
            Assert.AreEqual(4, removed.ID.Value);

            ContactFieldFilter filterState = new ContactFieldFilter();

            filterState.SetState("st5");
            Assert.IsTrue(store.Remove(filterState, out removed));
            Assert.AreEqual(5, removed.ID.Value);

            ContactFieldFilter filterZip = new ContactFieldFilter();

            filterZip.SetPostalCode("zip6");
            Assert.IsTrue(store.Remove(filterZip, out removed));
            Assert.AreEqual(6, removed.ID.Value);

            ContactFieldFilter filterId = new ContactFieldFilter();

            filterId.SetID(7);
            Assert.IsTrue(store.Remove(filterId, out removed));
            Assert.AreEqual(7, removed.ID.Value);

            Assert.AreEqual(0, store.Contacts.Count());
        }
        public void Menu()
        {
            Console.WriteLine("Size of List is " + store.ContactListSize);

            int flag = 1;

            while (flag != 0)
            {
                Console.WriteLine("\nType keywords to perform Action\n Add \tDisplay Search \tUpdate \tRemove \tExit");
                string choice = Console.ReadLine();
                switch (choice.ToLower())
                {
                case "add":
                    store.Add(ContactDetails());
                    break;

                case "display":
                    Display(store.ContactList);
                    break;

                case "search":
                    try
                    {
                        List <Contact> matching = store.Search(Console.ReadLine());
                        Display(matching);
                    }
                    catch (StudentNotFoundException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }

                    break;

                case "update":
                    Console.WriteLine("Ënter the name you want to update");
                    store.Update(Console.ReadLine());
                    break;

                case "remove":
                    store.Remove(Console.ReadLine());
                    Display(store.ContactList);
                    break;

                case "exit":
                    store.Serialize();
                    flag = 0;
                    break;

                default:
                    Console.WriteLine("Enter Proper KeyWord");
                    break;
                }
            }
        }
        public void RemoveWithFilterNoMatch()
        {
            ContactStore store      = new ContactStore();
            Contact      c1_with_id = store.Add(Contact.Create("fn1", "ln1", "street1", "city1", "st1", "zip1"));
            Contact      c2_with_id = store.Add(Contact.Create("fn2", "ln2", "street2", "city2", "st2", "zip2"));

            ContactFieldFilter filter = new ContactFieldFilter();

            filter.SetID(5);

            Contact removed;

            Assert.IsFalse(store.Remove(filter, out removed));
        }
        public CommandResult Execute()
        {
            List <Contact> removed = new List <Contact>();

            foreach (Contact c in contacts)
            {
                Contact r;
                if (store.Remove(c, out r))
                {
                    removed.Add(r);
                }
            }

            return(new NonUndoCommandResult(this, removed));
        }