Exemplo n.º 1
0
        public static void SaveDepartment(this IEntityRepository <Department> departmentRepository, Department dept)
        {
            departmentRepository.AddOrEdit(dept);

            var typeCollection = departmentRepository.GetAllRelevance <DepartmentTypeInDepartment>().Where(x => x.Department.ID == dept.ID).OrderBy(s => s.SortCode);

            foreach (var item in typeCollection)
            {
                departmentRepository.DeleteRelevance <DepartmentTypeInDepartment>(item);
            }

            var jobLeveClollection = departmentRepository.GetAllRelevance <JobLevelInDepartment>().Where(x => x.Department.ID == dept.ID).OrderBy(s => s.SortCode);

            foreach (var item in jobLeveClollection)
            {
                departmentRepository.DeleteRelevance <JobLevelInDepartment>(item);
            }

            var jobTitleCollection = departmentRepository.GetAllRelevance <JobTitleInDepartment>().Where(x => x.Department.ID == dept.ID).OrderBy(s => s.SortCode);

            foreach (var item in jobTitleCollection)
            {
                departmentRepository.DeleteRelevance <JobTitleInDepartment>(item);
            }

            foreach (var item in dept.Types)
            {
                var tItem = new DepartmentTypeInDepartment()
                {
                    Name = "", Department = dept, DepartmentType = item
                };
                departmentRepository.AddRelevance <DepartmentTypeInDepartment>(tItem);
            }
            foreach (var item in dept.JobLevels)
            {
                var tItem = new JobLevelInDepartment()
                {
                    Name = "", Department = dept, JobLevel = item
                };
                departmentRepository.AddRelevance <JobLevelInDepartment>(tItem);
            }
            foreach (var item in dept.JobTitles)
            {
                var tItem = new JobTitleInDepartment()
                {
                    Name = "", Department = dept, JobTitle = item
                };
                departmentRepository.AddRelevance <JobTitleInDepartment>(tItem);
            }

            departmentRepository.Save();
        }