using System; using System.Collections.Generic; using System.Linq; using System.Text; using EMIS.ViewModel.MinorManage.MinorClass; using System.Linq.Expressions; using EMIS.Entities; using EMIS.DataLogic.Repositories; using EMIS.ViewModel.MinorManage.MinorApply; using EMIS.ViewModel.MinorManage.MinorSetting; using EMIS.ViewModel.Students; using EMIS.ViewModel; namespace EMIS.DataLogic.MinorManage.MinorApply { public class StudentMinorRegistApplyDAL { public ClassminorRepository classminorRepository { get; set; } public GrademinorRepository grademinorRepository { get; set; } public SchoolyearRepository schoolyearRepository { get; set; } public CollegeRepository collegeRepository { get; set; } public MinorStandardSettingRepository minorStandardSettingRepository { get; set; } public UserRepository userRepository { get; set; } public StudentRepository studentRepository { get; set; } public ClassmajorRepository classmajorRepository { get; set; } public MinorControlRepository minorControlRepository { get; set; } public GrademajorRepository grademajorRepository { get; set; } public FacultymajorRepository facultymajorRepository { get; set; } public StudentMinorRegistRepository studentMinorRegistRepository { get;set; } public IQueryable GetMinorClassViewQueryable(Expression> exp, Guid userID, int? status) { var stuMinorResit = studentMinorRegistRepository.GetList(x => true); var query = from gr in grademinorRepository.GetList(exp) join sr in schoolyearRepository.Entities on gr.SchoolyearID equals sr.SchoolyearID join col in collegeRepository.Entities on gr.CollegeID equals col.CollegeID //join cla in classminorRepository.Entities //on gr.GrademinorID equals cla.GrademinorID //into gcla //from dcla in gcla.DefaultIfEmpty() select new GrademinorView { GrademinorID = gr.GrademinorID, SchoolyearID = gr.SchoolyearID, CollegeID = col.CollegeID, CollegeName = col.Name, CollegeNo = col.No, StudentLimit = gr.StudentLimit, SchoolyearCode = sr.Code, YearID = gr.YearID, StandardID = gr.StandardID, OpenStatus = gr.RecordStatus, ApplyNumber = gr.EM_StudentMinorRegist.Where(x => x.RecordStatus != status).Count(), ApplyStatus = stuMinorResit.Any(x => x.UserID == userID && x.GrademinorID == gr.GrademinorID && x.RecordStatus != status) ? true : false, CourseCount = gr.CF_GrademinorApplication.EM_MinorPlanApplication.Select(x => x.CoursematerialID).Count(), CanSelect = gr.RecordStatus == (int)CF_GrademinorStatus.Cancelled ? true : (stuMinorResit.Any(x => x.UserID == userID && x.GrademinorID == gr.GrademinorID && x.RecordStatus != status) ? false : true), RecordStatus = stuMinorResit.Any(x => x.UserID == userID && x.GrademinorID == gr.GrademinorID) ? stuMinorResit.Where(x => x.UserID == userID && x.GrademinorID == gr.GrademinorID).FirstOrDefault().RecordStatus : null, //cla.CF_ClassminorStudent.Any(x => x.UserID == userID) ? false : true, }; return query; } public int? GetStandardIDListByUserID(Guid userID) { var query = from stu in studentRepository.GetList(x => x.UserID == userID) join cla in classmajorRepository.Entities on stu.ClassmajorID equals cla.ClassmajorID select new { StandardID = cla.CF_Grademajor.CF_Facultymajor.StandardID, }; if (query.FirstOrDefault() != null) { return query.FirstOrDefault().StandardID; } return null; } public IQueryable GetMinorControlViewByUserIDAndSchoolyear(Guid userID, Guid schoolYearID) { var mrquery = from mcr in minorControlRepository.GetList(x => x.SchoolyearID == schoolYearID) select new MinorControlView { MinorControlID = mcr.MinorControlID, CollegeID = mcr.CollegeID, //CollegeName = cr.Name, SchoolyearID = mcr.SchoolyearID, //SchoolyearCode = year.Code, GradeYearID = mcr.GradeyearID, StartDate = mcr.StartDate, EndDate = mcr.EndDate }; var stuquery = from stu in studentRepository.GetList(x => x.UserID == userID) join cla in classmajorRepository.Entities on stu.ClassmajorID equals cla.ClassmajorID join gra in grademajorRepository.Entities on cla.GrademajorID equals gra.GrademajorID join fac in facultymajorRepository.Entities on gra.FacultymajorID equals fac.FacultymajorID join col in collegeRepository.Entities on fac.CollegeID equals col.CollegeID select new StudentsView { UserID = stu.UserID, CollegeID = col.CollegeID, Years = gra.GradeID, }; if (mrquery.Any(x => x.GradeYearID == stuquery.FirstOrDefault().Years)) { if (mrquery.Any(x => x.GradeYearID == stuquery.FirstOrDefault().Years && x.CollegeID == stuquery.FirstOrDefault().CollegeID)) { return mrquery.Where(x => x.GradeYearID == stuquery.FirstOrDefault().Years && x.CollegeID == stuquery.FirstOrDefault().CollegeID); } else { return mrquery.Where(x => x.GradeYearID == stuquery.FirstOrDefault().Years); } } else { return null; } } //public } }