Example #1
0
        private void submitButton_Click(object sender, System.EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(phoneNumberText.Text))
            {
                MessageBox.Show("You need to enter a phone number.");
                return;
            }

            currentPerson.FirstName    = firstNameText.Text;
            currentPerson.LastName     = lastNameText.Text;
            currentPerson.EmailAddress = emailText.Text;
            currentPerson.PhoneNumber  = phoneNumberText.Text;

            MongoCRUD db = new MongoCRUD(databaseName);

            if (currentPerson.Id == Guid.Empty)
            {
                var foundPeople = db.FindRecordByNames <PersonModel>(personTable, currentPerson.FirstName, currentPerson.LastName);

                if (foundPeople.Count > 0)
                {
                    foreach (var foundPerson in foundPeople)
                    {
                        currentPerson.Id = foundPerson.Id;
                        db.UpsertRecord(personTable, foundPerson.Id, currentPerson);
                    }
                }
                else
                {
                    db.InsertRecord(personTable, currentPerson);
                }
            }
            else
            {
                db.UpsertRecord(personTable, currentPerson.Id, currentPerson);
            }

            firstNameText.Text   = "";
            lastNameText.Text    = "";
            emailText.Text       = "";
            phoneNumberText.Text = "";
            currentPerson        = new PersonModel();
            LoadPersonData();
        }