コード例 #1
0
        public List<StudentSubject> GetStudentSubjects(User user, string studentId)
        {
            List<StudentSubject> list = new List<StudentSubject>();

            StudentSubjectDao = new StudentSubjectDao();

            //convert from business object to data access object
            int userIdToUse = 0;

            if (user.UserType == UserType.Employer)
            {
               // get it from student dao

                UserDao = new UserDao();
                 // go into data access open connection, bring query, fill in datatable
                DataTable resultDataTable = UserDao.GetUser("select * from WAE_LTU_USER where student_id='" + studentId + "'");

                if (resultDataTable.Rows.Count == 1)
                {
                    DataRow userRecord = resultDataTable.Rows[0];
                    userIdToUse = (int)userRecord.ItemArray[0];
                }
            }
            else if (user.UserType == UserType.Student)
            {
                userIdToUse = Convert.ToInt32(user.UserId);
            }
            else
            {
                throw new ArgumentOutOfRangeException();
            }

            DataAccess.Domain.User userData = new DataAccess.Domain.User { UserId = userIdToUse };

            List<DataAccess.Domain.StudentSubject> studentSubjectDataList = StudentSubjectDao.GetStudentSubjects(userData);

            // map list of data objects to business objects

            foreach (DataAccess.Domain.StudentSubject record in studentSubjectDataList)
            {
                var businessStudentSubject = new StudentSubject{ UserId = record.UserId, Assignment= record.Assignment, AssignmentName= record.AssignmentName, StudentSubjectId= record.StudentSubjectId, SubjectCode = record.SubjectCode, SubjectDescription = record.SubjectDescription, SubjectName= record.SubjectName};
                list.Add(businessStudentSubject);
            }

            return list;
        }