public ActionResult AssignPatient() { var model = new AssignPatientModel(); var db_logic = new DatabaseLogic(connection); model = db_logic.GetAssignPatientData(); return(View(model)); }
/* * GetAssignPatientData - AssignePatientModel * * Returns a model for the Assign patient controller, to be passed on to * the AssignPatient view. Takes all patients in the database and loads * their first and last names into the model, as well as their database * id numbers. * */ public AssignPatientModel GetAssignPatientData() { var model = new AssignPatientModel(); List <Patient> listOfPatients = new List <Patient>(); connection.Open(); string query = "SELECT * FROM ehr_patients"; //Create several lists to store the results //List indices will be constant for each patient List <string> first_names = new List <string>(); List <string> last_names = new List <string>(); List <int> db_ids = new List <int>(); //Create and execute database command MySqlCommand cmd = new MySqlCommand(query, connection); MySqlDataReader dataReader = cmd.ExecuteReader(); //load each patients info into our lists while (dataReader.Read()) { db_ids.Add(dataReader.GetInt32(0)); first_names.Add(dataReader.GetString(1)); last_names.Add(dataReader.GetString(2)); } connection.Close(); //load each patients data from the lists into a list the model will //accept for (int j = 0; j < first_names.Count(); j++) { Patient temp = new Patient { firstName = "", lastName = "" }; temp.databaseId = db_ids[j]; temp.firstName = first_names[j]; temp.lastName = last_names[j]; listOfPatients.Add(temp); } model.Patients = listOfPatients; return(model); }