예제 #1
0
        /// <summary>
        /// Returns a JobPost Object from the database
        /// </summary>
        /// <param name="id"></param>
        /// <returns>jobPost</returns>
        public JobPost Get(int id)
        {
            DbWorkHour    dbWorkHour    = new DbWorkHour();
            DbCompany     dbCompany     = new DbCompany();
            DbJobCategory dbJobCategory = new DbJobCategory();
            JobPost       jobPost       = new JobPost();

            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {
                connection.Open();
                using (SqlCommand cmd = connection.CreateCommand())
                {
                    cmd.CommandText = "SELECT * FROM JobPost WHERE Id = @Id";
                    cmd.Parameters.AddWithValue("Id", id);
                    SqlDataReader reader = cmd.ExecuteReader();
                    if (reader.Read())
                    {
                        jobPost.Id          = (int)reader["Id"];
                        jobPost.Title       = (string)reader["Title"];
                        jobPost.Description = (string)reader["Description"];
                        jobPost.StartDate   = (DateTime)reader["StartDate"];
                        jobPost.EndDate     = (DateTime)reader["EndDate"];
                        jobPost.JobTitle    = (string)reader["JobTitle"];
                        jobPost.workHours   = dbWorkHour.Get((int)reader["WorkHoursId"]);
                        jobPost.Address     = (string)reader["Address"];
                        jobPost.company     = dbCompany.Get((int)reader["CompanyId"]);
                        jobPost.jobCategory = dbJobCategory.Get((int)reader["JobCategoryId"]);
                    }
                    ;
                    return(jobPost);
                }
            }
        }
예제 #2
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 = conn.OpenConnection())
            {
                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);
        }