private void CreateNewProfile() { ProfileForm profileForm = new ProfileForm(); profileForm.ShowDialog(); if (profileForm.DialogResult == DialogResult.OK) { string loanProfileName = ""; loanProfileName = profileForm.Text; while (data.LoanProfiles.Any(x => x.Name == loanProfileName)) { loanProfileName = loanProfileName + "_duplicatename"; } LoanProfile loanProfile = new LoanProfile(); loanProfile.Name = loanProfileName; loanProfile.Loans = new List <Loan>(); data.LoanProfiles.Add(loanProfile); BindTreeView(); Program.UpdateDatabase(data); } }
private void EditProfile(LoanProfile sourceLoanProfile) { ProfileForm profileForm = new ProfileForm(sourceLoanProfile.Name); profileForm.ShowDialog(); if (profileForm.DialogResult == DialogResult.OK) { string loanProfileName = ""; loanProfileName = profileForm.Text; if (data.LoanProfiles.Any(x => x.Name == loanProfileName)) { MessageBox.Show("There is already a loan profile with the selected name. Please insert a different name.", "Loan profile already exists", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { LoanProfile changedProfile = data.LoanProfiles.SingleOrDefault(x => x.Name == sourceLoanProfile.Name); if (changedProfile != null) { changedProfile.Name = loanProfileName; foreach (var item in changedProfile.Loans) { item.LoanProfileName = loanProfileName; } data.SelectedLoan = new Loan(); BindTreeView(); BindSelectedLoan(); Program.UpdateDatabase(data); MessageBox.Show("Profile name has been successfully changed", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } }