Exemplo n.º 1
0
        /// <summary>
        /// Returns a list of all JobPost from the database
        /// </summary>
        /// <returns>a jobPostList</returns>
        public List <JobPost> GetAll()
        {
            List <JobPost> jobPostList = new List <JobPost>();

            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {
                connection.Open();
                using (SqlCommand cmd = connection.CreateCommand())
                {
                    cmd.CommandText = "SELECT * FROM JobPost";
                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        DbWorkHour    dbWorkHour    = new DbWorkHour();
                        DbCompany     dbCompany     = new DbCompany();
                        DbJobCategory dbJobCategory = new DbJobCategory();
                        JobPost       jobPost       = new JobPost
                        {
                            Id          = (int)reader["Id"],
                            Title       = (string)reader["Title"],
                            Description = (string)reader["Description"],
                            StartDate   = (DateTime)reader["StartDate"],
                            EndDate     = (DateTime)reader["EndDate"],
                            JobTitle    = (string)reader["JobTitle"],
                            workHours   = dbWorkHour.Get((int)reader["WorkHoursId"]),
                            Address     = (string)reader["Address"],
                            company     = dbCompany.Get((int)reader["CompanyId"]),
                            jobCategory = dbJobCategory.Get((int)reader["JobCategoryId"])
                        };
                        jobPostList.Add(jobPost);
                    }
                }
            }
            return(jobPostList);
        }