コード例 #1
0
        /// <summary>
        /// Gets all the departments from the database and returns them as a list of depart object.
        /// </summary>
        /// <param name="practitioners"></param>
        /// <returns> List of Department objects </returns>
        public List <Department> GetDepartments(List <Practitioner> practitioners)
        {
            List <Department> listOfDepartments = new List <Department>();

            using (SqlConnection connection = new SqlConnection(_connectionString))
            {
                connection.Open();
                SqlCommand commandDepartment = new SqlCommand("SPGetAllDepartments", connection);
                commandDepartment.CommandType = CommandType.StoredProcedure;

                SqlCommand commandRoom = new SqlCommand("SPGetRoomsFromDepartment", connection);
                commandRoom.CommandType = CommandType.StoredProcedure;

                SqlCommand commandPractitioners = new SqlCommand("SPGetPractitionersFromDepartment", connection);
                commandPractitioners.CommandType = CommandType.StoredProcedure;

                using (SqlDataReader reader = commandDepartment.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        Department tempDepartment = new Department(reader.GetValue(1).ToString(), reader.GetValue(2).ToString(), reader.GetInt32(0));

                        List <Room> tempRooms = new List <Room>();
                        commandRoom.Parameters.AddWithValue("DepartmentId", reader.GetInt32(0));
                        commandPractitioners.Parameters.AddWithValue("DepartmentId", reader.GetValue(0));

                        using (SqlDataReader readRoom = commandRoom.ExecuteReader())
                        {
                            while (readRoom.Read())
                            {
                                Room tempRoom = new Room(readRoom.GetString(1), default(DateTime), 24, readRoom.GetInt32(0));
                                tempRooms.Add(tempRoom);
                            }
                        }

                        using (SqlDataReader readPractitioners = commandPractitioners.ExecuteReader())
                        {
                            while (readPractitioners.Read())
                            {
                                Practitioner tempPractitioner = practitioners.Find(x => x.Id == readPractitioners.GetInt32(0));
                                tempDepartment.AddPractitioner(tempPractitioner);
                            }

                            tempDepartment.Rooms = tempRooms;

                            listOfDepartments.Add(tempDepartment);
                        }

                        commandRoom.Parameters.Clear();
                        commandPractitioners.Parameters.Clear();
                    }
                }
            }

            return(listOfDepartments);
        }
コード例 #2
0
        public void AddPractitionerTest()
        {
            Practitioner prac = new Practitioner(DateTime.Today, TimeSpan.FromHours(9));

            _testDepartment.AddPractitioner(prac);
        }