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;
        }
Exemple #2
0
        public AuthenticateUserResponseMessage AuthenticateUser(LoginRequestType type, string username, string password)
        {
            // go into data access get connection ( userdao )
            UserDao = new UserDao();
            // go into data access open connection, bring query, fill in datatable
            DataTable resultDataTable = UserDao.GetUser("select * from WAE_LTU_USER where username='******'");

            if (resultDataTable.Rows.Count == 1)
            {
                DataRow userRecord = resultDataTable.Rows[0];
                string retrievedUsername = (string)userRecord.ItemArray[1];
                string retrievedPassword = (string)userRecord.ItemArray[2];

                User user = new User{ UserId = userRecord.ItemArray[0].ToString(), Username = (string)userRecord.ItemArray[1], Password = (string)userRecord.ItemArray[2], Name = (string)userRecord.ItemArray[3], Email = (string)userRecord.ItemArray[4],  UserType = (string)userRecord.ItemArray[6]  };

                if (userRecord.ItemArray[5] != System.DBNull.Value) user.StudentId = (string)userRecord.ItemArray[5];

                if (type == LoginRequestType.OtherLoginRequest)
                {
                    if (username == retrievedUsername && password == retrievedPassword)
                    {

                        return new AuthenticateUserResponseMessage { IsValidUser = true, User = user };

                    }
                }

                if (type == LoginRequestType.AdminLoginRequest)
                {
                    if (username == retrievedUsername && password == retrievedPassword && user.UserType == "Admin")
                    {
                        return new AuthenticateUserResponseMessage { IsValidUser = true, User = user };
                    }
                }
            }

            return new AuthenticateUserResponseMessage { IsValidUser = false };
        }
Exemple #3
0
        public bool AddUser(User user)
        {
            UserDao = new UserDao();

            DataAccess.Domain.User dataUser = new DataAccess.Domain.User
            {
                Username = user.Username,
                Password = user.Password,
                Email = user.Email,
                Name = user.Name,
                StudentId = user.StudentId,
                UserType = user.UserType
            };

            int isUserCreated = UserDao.AddUser(dataUser);

               if (isUserCreated == 1)
            {
                    return true;
            }

            return false;
        }