public void SaveABI(AdultBasicInfoClass abi, AdultBasicInfoTextValidation abiCheck) { string query = $"Update AdultBasicInfo Set "; List <string> listToSave = new List <string>(new string[] { "lastName = @LastName", "firstName = @FirstName", "middleInitial = @MiddleInitial", "preferredName = @PreferredName", "program = @Program", "streetAddress = @StreetAddress", "city = @City", "state = @State", "zipCode = @ZipCode", "primaryPhoneNum = @PrimaryPhoneNum", "cellPhoneNum = @CellPhoneNum", "hispanicOrLatino = @HispanicOrLatino", "race = @Race", "gender = @Gender", "dateOfBirth = @DateOfBirth", "SSN = @ssn", "completedEdLevel = @CompletedEdLevel", "attendedCollegeOrTech = @AttendedCollegeOrTech", "liveWithParent = @LiveWithParent" }); List <string> toRemove = abiCheck.IsValid; foreach (var v in toRemove) { for (int i = 0; i < listToSave.Count; i++) { if (listToSave[i].Contains(v)) { listToSave.RemoveAt(i); i--; } } } foreach (var s in listToSave) { if (listToSave.IndexOf(s) != listToSave.Count - 1) { query += s + ","; } else { query += s; } } query += " Where Id = @id"; using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(Helper.CnnVal("EnrollmentDB"))) { connection.Execute(query, new { LastName = abi.lastName, FirstName = abi.firstName, MiddleInitial = abi.middleInitial, PreferredName = abi.preferredName, Program = abi.program, StreetAddress = abi.streetAddress, City = abi.city, State = abi.state, ZipCode = abi.zipCode, PrimaryPhoneNum = abi.primaryPhoneNum, CellPhoneNum = abi.cellPhoneNum, HispanicOrLatino = abi.hispanicOrLatino, Race = abi.race, Gender = abi.gender, DateOfBirth = abi.dateOfBirth, ssn = abi.SSN, CompletedEdLevel = abi.completedEdLevel, AttendedCollegeOrTech = abi.attendedCollegeOrTech, LiveWithParent = abi.liveWithParent, id = abi.Id }); } }