예제 #1
0
        public static int SaveClinicians(List <ClinicianModel> clinicianModels, List <string> errors)
        {
            string sqlStatement = @"INSERT into dbo.Clinician (HCPId, Password)
                    values (@HCPId, @Password)";

            int successfulInserts = SqlDataAccess.SaveList <ClinicianModel>(sqlStatement, clinicianModels);

            if (successfulInserts != clinicianModels.Count)
            {
                errors.Add("Error storing the provided Clinician credentials, all changes were reverted. \nCheck that the HCP Id's provided are unique.");
            }

            // This was an attempt but SaveList returns 0 if any errors are detected, even if rows are inserted
            //int failedIndex = successfulInserts;
            //int lastIndex = clinicianModels.Count - 1;

            //while (failedIndex <= lastIndex)
            //{
            //    errors.Add($"Error storing Clinician {clinicianModels[failedIndex].HCPId}, a record already exists with that ID.");

            //    // If the current index is now the last index, that means the error was on the last index, so break as there is nothing more to process
            //    if(failedIndex == lastIndex)
            //    {
            //        break;
            //    }

            //    ++failedIndex;
            //    int iterativeSuccess = SqlDataAccess.SaveList<ClinicianModel>(sqlStatement, clinicianModels.GetRange(failedIndex, 1 + lastIndex - failedIndex));
            //    successfulInserts += iterativeSuccess;
            //    failedIndex += iterativeSuccess;
            //}

            return(successfulInserts);
        }
예제 #2
0
        public static int SavePatients(List <PatientModel> patientModels, List <string> errorMessages)
        {
            string sqlStatement = @"INSERT into dbo.Patient (NHSNumber, Password)
                    values (@NHSNumber, @Password)";

            int successfulInserts = SqlDataAccess.SaveList <PatientModel>(sqlStatement, patientModels);

            if (successfulInserts != patientModels.Count)
            {
                errorMessages.Add("Error storing the provided Patient credentials, all changes were reverted. \nCheck that the NHS Number's provided are unique.");
            }

            return(successfulInserts);
        }