/// <summary>
        /// The DeleteBtn_Click event handler on this Page is used to delete an
        /// a contact.  It  uses the Rainbow.ContactsDB()
        /// data component to encapsulate all data functionality.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        protected override void OnDelete(EventArgs e)
        {
            base.OnDelete(e);

            // Only attempt to delete the item if it is an existing item
            // (new items will have "ItemID" of 0)

            if (ItemID != 0)
            {
                ContactsDB contacts = new ContactsDB();
                contacts.DeleteContact(ItemID);
            }

            // Redirect back to the portal home page
            RedirectBackToReferringPage();
        }
Example #2
0
        public ContactsViewModel()
        {
            saveContact = new Contact();

            if (cDB.Count() == 0)
            {
                cDB.AddContact("Marvin", "Cochise", "Friend");
                cDB.AddContact("Bill", "Smith", "Friend");
                cDB.AddContact("Hugh", "Lowell", "Friend");
                cDB.AddContact("Josie", "Ficka", "Friend");
                cDB.AddContact("Pasha", "Netsky", "Russian");
                cDB.AddContact("Quana", "Parker", "Chief");
            }
            AddContactCommand = new Command(() =>
            {
                cDB.AddContact(conContact.FirstName, conContact.LastName, conContact.ContactType);
                Console.WriteLine("cDB.count: " + cDB.Count());

                Contact = new Contact();
            });

            SaveEditCommand = new Command(() =>
            {
                cDB.UpdateContact(selectedContact.ID, selectedContact.FirstName, selectedContact.LastName, selectedContact.ContactType); //'Object reference not set to an instance of an object.'
            });

            DeleteCommand = new Command(() =>
            {
                cDB.DeleteContact(SelectedContact.ID);
            });

            CancelEditCommand = new Command(() =>
            {
                cDB.UpdateContact(saveContact.ID, saveContact.FirstName, saveContact.LastName, saveContact.ContactType);
            });
        }
Example #3
0
        public bool DeleteContact(int id)
        {
            ContactsDB contactsDB = new ContactsDB();

            return(contactsDB.DeleteContact(id));
        }