using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Linq.Expressions; using Bowin.Common.Linq; using Bowin.Common.Linq.Entity; using EMIS.DataLogic.UniversityManage.TeacherManage; using EMIS.DataLogic.ExaminationManage; using EMIS.Entities; using EMIS.ViewModel; using EMIS.ViewModel.UniversityManage.TeacherManage; using EMIS.CommonLogic.EducationSchedule; namespace EMIS.CommonLogic.ExaminationManage { public class ExaminationTeacherServices : BaseServices, IExaminationTeacherServices { public StaffDAL StaffDAL { get; set; } public ExaminationTeacherDAL ExaminationTeacherDAL { get; set; } public ExaminationPlanDAL ExaminationPlanDAL { get; set; } public Lazy ScheduleServices { get; set; } public IGridResultSet GetStaffViewList(ConfiguretView teacherView, Guid? campusID, Guid? collegeID, Guid? departmentID, int pageIndex, int pageSize) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && x.EX_ExaminationTeacher.Count() > 0); if (campusID.HasValue) { exp = exp.And(x => x.CF_College.CampusID == campusID); } if (collegeID.HasValue) { exp = exp.And(x => x.CollegeID == collegeID); } if (departmentID.HasValue) { exp = exp.And(x => x.DepartmentID == departmentID); } var q = StaffDAL.GetStaffViewQueryable(exp); if (!string.IsNullOrEmpty(teacherView.ConditionValue) && !string.IsNullOrEmpty(teacherView.Attribute)) q = q.DynamicWhere(teacherView.Attribute, teacherView.Condition, teacherView.ConditionValue); return GetQueryByDataRangeByCollege(q).OrderByDescending(x => x.CollegeName).ThenByDescending(x => x.IncumbencyState).ThenByDescending(x => x.Name) .ToGridResultSet(pageIndex, pageSize); } public IList GetStaffViewList(ConfiguretView teacherView, Guid? campusID, Guid? collegeID, Guid? departmentID) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && x.EX_ExaminationTeacher.Count() > 0); if (campusID.HasValue) { exp = exp.And(x => x.CF_College.CampusID == campusID); } if (collegeID.HasValue) { exp = exp.And(x => x.CollegeID == collegeID); } if (departmentID.HasValue) { exp = exp.And(x => x.DepartmentID == departmentID); } var q = StaffDAL.GetStaffViewQueryable(exp); if (!string.IsNullOrEmpty(teacherView.ConditionValue) && !string.IsNullOrEmpty(teacherView.Attribute)) q = q.DynamicWhere(teacherView.Attribute, teacherView.Condition, teacherView.ConditionValue); return GetQueryByDataRangeByCollege(q).OrderByDescending(x => x.CollegeName).ThenByDescending(x => x.IncumbencyState).ThenByDescending(x => x.Name) .ToList(); } public void Add(IList userIDList) { foreach (var userID in userIDList) { var examinationTeacherEntity = ExaminationTeacherDAL.ExaminationTeacherRepository.GetSingle(x => x.UserID == userID); if (examinationTeacherEntity == null) { examinationTeacherEntity = new EX_ExaminationTeacher(); examinationTeacherEntity.ExaminationTeacherID = Guid.NewGuid(); examinationTeacherEntity.UserID = userID; this.SetNewStatus(examinationTeacherEntity); UnitOfWork.Add(examinationTeacherEntity); } } UnitOfWork.Commit(); } public void Delete(IList userIDList) { if (userIDList.Count > 0) { UnitOfWork.Delete(x => userIDList.Contains(x.UserID)); } } public IGridResultSet GetAvailableStaffViewList(ConfiguretView teacherView, Guid examinationPlanID, Guid classroomID, Guid? campusID, Guid? collegeID, Guid? departmentID, int pageIndex, int pageSize) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && x.EX_ExaminationTeacher.Count() > 0); if (campusID.HasValue) { exp = exp.And(x => x.CF_College.CampusID == campusID); } if (collegeID.HasValue) { exp = exp.And(x => x.CollegeID == collegeID); } if (departmentID.HasValue) { exp = exp.And(x => x.DepartmentID == departmentID); } var examinationPlan = ExaminationPlanDAL.ExaminationPlanRepository.GetSingle(x => x.ExaminationPlanID == examinationPlanID); var scheduleDateTimeList = new List { new StartEndTimeView { StartTime = examinationPlan.ExaminationDate.Value.Add(examinationPlan.StartTime.Value) , EndTime = examinationPlan.ExaminationDate.Value.Add(examinationPlan.EndTime.Value) } }; var schedulingList = this.ScheduleServices.Value.GetEducationSchedulingWeekNumViewForExaminationTeacher(examinationPlan.SchoolyearID.Value, scheduleDateTimeList); var scheduledTeacherIDList = schedulingList.SelectMany(x => x.TeacherList).Select(x => x.UserID).Distinct().ToList(); exp = exp.And(x => !scheduledTeacherIDList.Contains(x.UserID)); var q = ExaminationTeacherDAL.GetAvailableStaffView((x => x.ExaminationPlanID == examinationPlanID), classroomID, exp); if (!string.IsNullOrEmpty(teacherView.ConditionValue) && !string.IsNullOrEmpty(teacherView.Attribute)) q = q.DynamicWhere(teacherView.Attribute, teacherView.Condition, teacherView.ConditionValue); return GetQueryByDataRangeByCollege(q).OrderByDescending(x => x.CollegeName).ThenByDescending(x => x.IncumbencyState).ThenByDescending(x => x.Name) .ToGridResultSet(pageIndex, pageSize); } public IGridResultSet GetAddAvailableStaffViewList(ConfiguretView teacherView, Guid classroomID, Guid? campusID, Guid? collegeID, Guid? departmentID, int pageIndex, int pageSize) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && x.EX_ExaminationTeacher.Count() > 0); if (campusID.HasValue) { exp = exp.And(x => x.CF_College.CampusID == campusID); } if (collegeID.HasValue) { exp = exp.And(x => x.CollegeID == collegeID); } if (departmentID.HasValue) { exp = exp.And(x => x.DepartmentID == departmentID); } var q = ExaminationTeacherDAL.GetAvailableStaffView((x => true), classroomID, exp); if (!string.IsNullOrEmpty(teacherView.ConditionValue) && !string.IsNullOrEmpty(teacherView.Attribute)) q = q.DynamicWhere(teacherView.Attribute, teacherView.Condition, teacherView.ConditionValue); return GetQueryByDataRangeByCollege(q).OrderByDescending(x => x.CollegeName).ThenByDescending(x => x.IncumbencyState).ThenByDescending(x => x.Name) .ToGridResultSet(pageIndex, pageSize); } public IGridResultSet GetAvailableStaffViewGdssList(ConfiguretView teacherView, Guid schoolyearID, DateTime examinationDate, TimeSpan startTime, TimeSpan endTime, Guid classroomID, Guid? campusID, Guid? collegeID, Guid? departmentID, int pageIndex, int pageSize) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE && x.EX_ExaminationTeacher.Count() > 0); if (campusID.HasValue) { exp = exp.And(x => x.CF_College.CampusID == campusID); } if (collegeID.HasValue) { exp = exp.And(x => x.CollegeID == collegeID); } if (departmentID.HasValue) { exp = exp.And(x => x.DepartmentID == departmentID); } var scheduleDateTimeList = new List { new StartEndTimeView { StartTime = examinationDate.Add(startTime) , EndTime = examinationDate.Add(endTime) } }; var schedulingList = this.ScheduleServices.Value.GetEducationSchedulingWeekNumViewForExaminationTeacher(schoolyearID, scheduleDateTimeList); var scheduledTeacherIDList = schedulingList.SelectMany(x => x.TeacherList).Select(x => x.UserID).Distinct().ToList(); exp = exp.And(x => !scheduledTeacherIDList.Contains(x.UserID)); var q = ExaminationTeacherDAL.GetAvailableStaffViewGdss((x => x.SchoolyearID == schoolyearID && x.ExaminationDate == examinationDate && x.StartTime <= endTime && x.EndTime >= startTime), classroomID, exp); if (!string.IsNullOrEmpty(teacherView.ConditionValue) && !string.IsNullOrEmpty(teacherView.Attribute)) q = q.DynamicWhere(teacherView.Attribute, teacherView.Condition, teacherView.ConditionValue); return GetQueryByDataRangeByCollege(q).OrderByDescending(x => x.CollegeName).ThenByDescending(x => x.IncumbencyState).ThenByDescending(x => x.Name) .ToGridResultSet(pageIndex, pageSize); } } }