using System; using System.Collections.Generic; using System.Linq; using System.Text; using EMIS.DataLogic.Repositories; using EMIS.ViewModel.TerminatePrinter; using System.Linq.Expressions; using EMIS.Entities; namespace EMIS.DataLogic.TerminatePrinter { public class StudentPrintTimesDAL { public StudentPrintTimesRepository StudentPrintTimesRepository { get; set; } public StudentRepository StudentRepository { get; set; } public ClassmajorRepository ClassmajorRepository { get; set; } public GrademajorRepository GrademajorRepository { get; set; } public FacultymajorRepository FacultymajorRepository { get; set; } public CollegeRepository CollegeRepository { get; set; } public UserRepository UserRepository { get; set; } public InSchoolSettingRepository InSchoolSettingRepository { get; set; } public PrintControlRepository PrintControlRepository { get; set; } public IQueryable GetStudentPrintTimesViewQueryable(Expression> facultyExp, Expression> gradeExp, Expression> classExp) { var query = from times in StudentPrintTimesRepository.Entities from student in StudentRepository.Entities.Where(x => times.UserID == x.UserID) from user in UserRepository.Entities.Where(x => student.UserID == x.UserID) from classmajor in ClassmajorRepository.Entities.Where(classExp).Where(x => student.ClassmajorID == x.ClassmajorID) from grade in GrademajorRepository.Entities.Where(gradeExp).Where(x => classmajor.GrademajorID == x.GrademajorID) from faculty in FacultymajorRepository.Entities.Where(facultyExp).Where(x => grade.FacultymajorID == x.FacultymajorID) from college in CollegeRepository.Entities.Where(x => faculty.CollegeID == x.CollegeID) from inschool in InSchoolSettingRepository.Entities.Where(x => student.InSchoolStatusID == x.InSchoolStatusID) select new StudentPrintTimesView { StudentPrintTimesID = times.StudentPrintTimesID, CollegeID = college.CollegeID, CollegeNo = college.No, CollegeName = college.Name, YearID = grade.GradeID, StandardID = faculty.StandardID, ClassmajorID = classmajor.ClassmajorID, ClassmajorNo = classmajor.No, ClassmajorName = classmajor.Name, UserID = student.UserID, LoginID = user.LoginID, Name = user.Name, IsInSchool = inschool.IsSelected, Times = times.Times, RecordStatus = times.RecordStatus, CreateUserID = times.CreateUserID, CreateTime = times.CreateTime, ModifyUserID = times.ModifyUserID, ModifyTime = times.ModifyTime }; return query; } public IQueryable GetStudentPrintMessageViewQueryable(Expression> exp) { var query = (from user in UserRepository.GetList(exp) from student in StudentRepository.Entities.Where(x => user.UserID == x.UserID) from classmajor in ClassmajorRepository.Entities.Where(x => student.ClassmajorID == x.ClassmajorID) from grade in GrademajorRepository.Entities.Where(x => classmajor.GrademajorID == x.GrademajorID) from inschool in InSchoolSettingRepository.Entities.Where(x => student.InSchoolStatusID == x.InSchoolStatusID) .DefaultIfEmpty() from control in PrintControlRepository.Entities.Where(x => grade.GradeID == x.YearID) .DefaultIfEmpty() from times in StudentPrintTimesRepository.Entities.Where(x => user.UserID == x.UserID) .DefaultIfEmpty() select new StudentPrintMessageView { UserID = user.UserID, TotalPrintTimes = (inschool.IsSelected == true) ? (control.Times ?? 0) : 0, PrintTimes = (times.Times ?? 0) } ); return query; } } }