/// <summary>
        /// 부서-소속원 정보 (<see cref="DepartmentMember"/>)를 검색하기 위한 Criteria를 빌드합니다.
        /// </summary>
        public QueryOver<DepartmentMember, DepartmentMember> BuildQueryOverOfDepartmentMember(
            Department department, User user, EmployeeTitle employeeTitle, bool? isLeader, bool? isActive)
        {
            if(IsDebugEnabled)
                log.Debug(@"부서-소속원 정보 (DepartmentMember)를 검색하기 위한 Criteria를 빌드합니다... " +
                          @"department={0}, user={1}, employeeTitle={2}, isLeader={3}, isActive={4}",
                          department, user, employeeTitle, isLeader, isActive);

            var query = QueryOver.Of<DepartmentMember>();

            if(department != null)
                query.AddWhere(dm => dm.Department == department);

            if(user != null)
                query.AddWhere(dm => dm.User == user);

            if(employeeTitle != null)
                query.AddWhere(dm => dm.EmployeeTitle == employeeTitle);

            if(isLeader.HasValue)
                query.AddWhere(dm => dm.IsLeader == isLeader);

            if(isActive.HasValue)
                query.AddNullAsTrue(dm => dm.IsActive, isActive);

            return query;
        }
        /// <summary>
        /// 사원 직책 정보를 생성합니다.
        /// </summary>
        /// <param name="company"></param>
        /// <param name="code"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public EmployeeTitle CreateEmployeeTitle(Company company, string code, string name)
        {
            var title = new EmployeeTitle(company, code) {Name = name};

            if(IsDebugEnabled)
                log.Debug("새로운 EmployeeTitle을 생성합니다... " + title);

            return Repository<EmployeeTitle>.SaveOrUpdate(title);
        }
 /// <summary>
 /// 부서-소속원 정보 (<see cref="DepartmentMember"/>)를 검색하기 위한 Criteria를 빌드합니다.
 /// </summary>
 public DetachedCriteria BuildCriteriaOfDepartmentMember(Department department, User user,
                                                         EmployeeTitle employeeTitle, bool? isLeader, bool? isActive)
 {
     return BuildQueryOverOfDepartmentMember(department, user, employeeTitle, isLeader, isActive).DetachedCriteria;
 }
        /// <summary>
        /// 부서에 직원 소속 정보를 생성합니다.
        /// </summary>
        /// <param name="department">부서</param>
        /// <param name="user">사용자</param>
        /// <param name="employeeTitle">직책 정보</param>
        /// <returns></returns>
        public DepartmentMember CreateDepartmentMember(Department department, User user, EmployeeTitle employeeTitle)
        {
            department.ShouldNotBeNull("department");
            user.ShouldNotBeNull("user");

            DepartmentMember member;

            // 1. 이미 부서에 소속되어 있다면, 정보 갱신만 하고, 반환한다.
            if(IsDepartmentMember(department, user))
            {
                if(log.IsInfoEnabled)
                    log.Info("이미 부서에 소속된 직원이므로, 새로 생성하지 않고 기존 정보를 읽어 반환합니다. department={0}, user={1}", department, user);

                member = department.Members.FirstOrDefault(m => m.User.Equals(user));
                // member = department.Members.Where(m => m.User.Equals(user)).FirstOrDefault();

                if(member != null && member.EmployeeTitle != employeeTitle)
                {
                    member.EmployeeTitle = employeeTitle;
                    Repository<DepartmentMember>.SaveOrUpdate(member);
                }

                return member;
            }

            // 2. 새로운 부서 소속 정보를 생성하고, 저장한 후 반환한다.
            if(IsDebugEnabled)
                log.Debug(@"부서에 새로운 직원을 소속시킵니다. department={0}, user={1}, employeeTitle={2}",
                          department.Id, user.Id, employeeTitle);

            var company = department.Company;
            Guard.Assert(company != null, @"해당 Company 정보를 찾을 수 없습니다. department=[{0}]", department);

            member = new DepartmentMember(department, user)
                     {
                         EmployeeTitle = employeeTitle
                     };

            return Repository<DepartmentMember>.SaveOrUpdate(member);
        }