/// <summary> /// Returns a list of JobApplication from the database, that has the corosponding ApplierId from the Applier /// </summary> /// <param name="ApplierId"></param> /// <returns></returns> public List <JobApplication> GetAllByApplierId(int ApplierId) { using (SqlConnection connection = new SqlConnection(ConnectionString)) { connection.Open(); using (SqlCommand cmd = connection.CreateCommand()) { cmd.CommandText = "SELECT * FROM JobApplication WHERE ApplierId = @ApplierId"; cmd.Parameters.AddWithValue("ApplierId", ApplierId); SqlDataReader reader = cmd.ExecuteReader(); DbApplier dbApplier = new DbApplier(); List <JobApplication> jobApplicationList = new List <JobApplication>(); while (reader.Read()) { JobApplication jobApplication = new JobApplication((int)reader["Id"], (string)reader["Title"], (string)reader["Description"], dbApplier.Get((int)reader["ApplierId"])); jobApplicationList.Add(jobApplication); } return(jobApplicationList); } } }
/// <summary> /// Returns a specific JobApplication by the given id /// </summary> /// <param name="id"></param> /// <returns>JobApplication</returns> public JobApplication Get(int id) { using (SqlConnection connection = new SqlConnection(ConnectionString)) { connection.Open(); using (SqlCommand cmd = connection.CreateCommand()) { cmd.CommandText = "SELECT * FROM JobApplication WHERE Id = @Id"; cmd.Parameters.AddWithValue("Id", id); SqlDataReader reader = cmd.ExecuteReader(); DbApplier dbApplier = new DbApplier(); if (reader.Read()) { JobApplication jobApplication = new JobApplication((int)reader["Id"], (string)reader["Title"], (string)reader["Description"], dbApplier.Get((int)reader["ApplierId"])); return(jobApplication); } else { return(null); } } } }