/// <summary>
        /// The UpdateBtn_Click event handler on this Page is used to either
        /// create or update 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 OnUpdate(EventArgs e)
        {
            base.OnUpdate(e);

            // Only Update if Entered data is Valid
            if (Page.IsValid == true)
            {
                // Create an instance of the ContactsDB component
                ContactsDB contacts = new ContactsDB();

                if (ItemID == 0)
                {
                    // Add the contact within the contacts table
                    contacts.AddContact(ModuleID, ItemID, PortalSettings.CurrentUser.Identity.Email, NameField.Text,
                                        RoleField.Text, EmailField.Text, Contact1Field.Text, Contact2Field.Text,
                                        FaxField.Text, AddressField.Text);
                }
                else
                {
                    // Update the contact within the contacts table
                    contacts.UpdateContact(ModuleID, ItemID, PortalSettings.CurrentUser.Identity.Email, NameField.Text,
                                           RoleField.Text, EmailField.Text, Contact1Field.Text, Contact2Field.Text,
                                           FaxField.Text, AddressField.Text);
                }

                // Redirect back to the portal home page
                RedirectBackToReferringPage();
            }
        }
Esempio n. 2
0
        public bool UpdateContact(Contact contact)
        {
            _contact = contact;
            ContactsDB contactsDB = new ContactsDB();

            Validate();
            return(ValidationErrors.Count == 0 ? contactsDB.UpdateContact(contact) : false);
        }
Esempio n. 3
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);
            });
        }