Пример #1
0
        public void SaveAEC(AdultEmergencyContactClass aec, AdultECUCTextValidation aecCheck)
        {
            string        query      = $"Update AdultEmergencyContact Set ";
            List <string> listToSave = new List <string>(new string[] { "contactName = @ContactName", "relationship = @Relationship", "primaryNum = @PrimaryNum", "alternateNum = @AlternateNum", "nameNearestRelative = @NameNearestRelative", "NRrelationship = @nrRelationship", "NRstreetAddress = @nrStreetAddress", "NRcity = @nrCity", "NRstate = @nrState", "NRzip = @nrZip", "NRprimaryNum = @nrPrimaryNum", "NRworkNum = @nrWorkNum", "NRcellNum = @nrCellNum" });
            List <string> toRemove   = aecCheck.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";

            if (query.Contains("Set  Where"))
            {
                return;
            }

            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(Helper.CnnVal("EnrollmentDB")))
            {
                connection.Execute(query,
                                   new { ContactName = aec.contactName, Relationship = aec.relationship, PrimaryNum = aec.primaryNum, AlternateNum = aec.alternateNum, NameNearestRelative = aec.nameNearestRelative, nrRelationship = aec.NRrelationship, nrStreetAddress = aec.NRstreetAddress, nrCity = aec.NRcity, nrState = aec.NRstate, nrZip = aec.NRzip, nrPrimaryNum = aec.NRprimaryNum, nrWorkNum = aec.NRworkNum, nrCellNum = aec.NRcellNum, id = aec.Id });
            }
        }