/* * Used to populate the table in the event endpoint */ public static EventTableDetails getEventTableDetails(int eventID) { EventTableDetails details = new EventTableDetails(); DataRowCollection rows = MVCFullCalendarDemo.Models.Event.getShiftsByEventID(eventID); details.volunteers = new VolunteerIdentifier[rows.Count]; details.shifts = rows; //Iterate through the list of shifts for (int i = 0; i < rows.Count; i++) { DataRow row = rows[i]; //Need to get the id of the volunteer for each shift and get the volunteers name //If there are no volunteers then the volunteers array will remain empty if (row["UserID"] != null) { VolunteerIdentifier vi = getVolunteerByID((int)row["UserID"]); details.volunteers[i] = vi; } } return(details); }
/* * Helper function to query the database for a volunteer based off their id **/ private static VolunteerIdentifier getVolunteerByID(int id) { VolunteerIdentifier volunteer = new VolunteerIdentifier(); DataTable userTable = new DataTable(); var cn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); DataRowCollection rows; using (cn) { string _sql = @"SELECT * FROM UserTable WHERE id = '" + id + "'"; var cmd = new SqlCommand(_sql, cn); cn.Open(); userTable.Load(cmd.ExecuteReader()); rows = userTable.Rows; foreach (DataRow row in rows) { volunteer.firstName = Convert.ToString(row["FirstName"]); volunteer.lastName = Convert.ToString(row["LastName"]); } cn.Close(); } return(volunteer); }