StudentMinorRegistApplyDAL.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.ViewModel.MinorManage.MinorClass;
  6. using System.Linq.Expressions;
  7. using EMIS.Entities;
  8. using EMIS.DataLogic.Repositories;
  9. using EMIS.ViewModel.MinorManage.MinorApply;
  10. using EMIS.ViewModel.MinorManage.MinorSetting;
  11. using EMIS.ViewModel.Students;
  12. using EMIS.ViewModel;
  13. namespace EMIS.DataLogic.MinorManage.MinorApply
  14. {
  15. public class StudentMinorRegistApplyDAL
  16. {
  17. public ClassminorRepository classminorRepository { get; set; }
  18. public GrademinorRepository grademinorRepository { get; set; }
  19. public SchoolyearRepository schoolyearRepository { get; set; }
  20. public CollegeRepository collegeRepository { get; set; }
  21. public MinorStandardSettingRepository minorStandardSettingRepository { get; set; }
  22. public UserRepository userRepository { get; set; }
  23. public StudentRepository studentRepository { get; set; }
  24. public ClassmajorRepository classmajorRepository { get; set; }
  25. public MinorControlRepository minorControlRepository { get; set; }
  26. public GrademajorRepository grademajorRepository { get; set; }
  27. public FacultymajorRepository facultymajorRepository { get; set; }
  28. public StudentMinorRegistRepository studentMinorRegistRepository { get;set; }
  29. public IQueryable<GrademinorView> GetMinorClassViewQueryable(Expression<Func<CF_Grademinor, bool>> exp, Guid userID, int? status)
  30. {
  31. var stuMinorResit = studentMinorRegistRepository.GetList(x => true);
  32. var query = from gr in grademinorRepository.GetList(exp)
  33. join sr in schoolyearRepository.Entities
  34. on gr.SchoolyearID equals sr.SchoolyearID
  35. join col in collegeRepository.Entities
  36. on gr.CollegeID equals col.CollegeID
  37. //join cla in classminorRepository.Entities
  38. //on gr.GrademinorID equals cla.GrademinorID
  39. //into gcla
  40. //from dcla in gcla.DefaultIfEmpty()
  41. select new GrademinorView
  42. {
  43. GrademinorID = gr.GrademinorID,
  44. SchoolyearID = gr.SchoolyearID,
  45. CollegeID = col.CollegeID,
  46. CollegeName = col.Name,
  47. CollegeNo = col.No,
  48. StudentLimit = gr.StudentLimit,
  49. SchoolyearCode = sr.Code,
  50. YearID = gr.YearID,
  51. StandardID = gr.StandardID,
  52. OpenStatus = gr.RecordStatus,
  53. ApplyNumber = gr.EM_StudentMinorRegist.Where(x => x.RecordStatus != status).Count(),
  54. ApplyStatus = stuMinorResit.Any(x => x.UserID == userID && x.GrademinorID == gr.GrademinorID && x.RecordStatus != status) ? true : false,
  55. CourseCount = gr.CF_GrademinorApplication.EM_MinorPlanApplication.Select(x => x.CoursematerialID).Count(),
  56. CanSelect = gr.RecordStatus == (int)CF_GrademinorStatus.Cancelled ? true : (stuMinorResit.Any(x => x.UserID == userID && x.GrademinorID == gr.GrademinorID && x.RecordStatus != status) ? false : true),
  57. RecordStatus = stuMinorResit.Any(x => x.UserID == userID && x.GrademinorID == gr.GrademinorID) ? stuMinorResit.Where(x => x.UserID == userID && x.GrademinorID == gr.GrademinorID).FirstOrDefault().RecordStatus : null,
  58. //cla.CF_ClassminorStudent.Any(x => x.UserID == userID) ? false : true,
  59. };
  60. return query;
  61. }
  62. public int? GetStandardIDListByUserID(Guid userID)
  63. {
  64. var query = from stu in studentRepository.GetList(x => x.UserID == userID)
  65. join cla in classmajorRepository.Entities
  66. on stu.ClassmajorID equals cla.ClassmajorID
  67. select new
  68. {
  69. StandardID = cla.CF_Grademajor.CF_Facultymajor.StandardID,
  70. };
  71. if (query.FirstOrDefault() != null)
  72. {
  73. return query.FirstOrDefault().StandardID;
  74. }
  75. return null;
  76. }
  77. public IQueryable<MinorControlView> GetMinorControlViewByUserIDAndSchoolyear(Guid userID, Guid schoolYearID)
  78. {
  79. var mrquery = from mcr in minorControlRepository.GetList(x => x.SchoolyearID == schoolYearID)
  80. select new MinorControlView
  81. {
  82. MinorControlID = mcr.MinorControlID,
  83. CollegeID = mcr.CollegeID,
  84. //CollegeName = cr.Name,
  85. SchoolyearID = mcr.SchoolyearID,
  86. //SchoolyearCode = year.Code,
  87. GradeYearID = mcr.GradeyearID,
  88. StartDate = mcr.StartDate,
  89. EndDate = mcr.EndDate
  90. };
  91. var stuquery = from stu in studentRepository.GetList(x => x.UserID == userID)
  92. join cla in classmajorRepository.Entities
  93. on stu.ClassmajorID equals cla.ClassmajorID
  94. join gra in grademajorRepository.Entities
  95. on cla.GrademajorID equals gra.GrademajorID
  96. join fac in facultymajorRepository.Entities
  97. on gra.FacultymajorID equals fac.FacultymajorID
  98. join col in collegeRepository.Entities
  99. on fac.CollegeID equals col.CollegeID
  100. select new StudentsView
  101. {
  102. UserID = stu.UserID,
  103. CollegeID = col.CollegeID,
  104. Years = gra.GradeID,
  105. };
  106. if (mrquery.Any(x => x.GradeYearID == stuquery.FirstOrDefault().Years))
  107. {
  108. if (mrquery.Any(x => x.GradeYearID == stuquery.FirstOrDefault().Years && x.CollegeID == stuquery.FirstOrDefault().CollegeID))
  109. {
  110. return mrquery.Where(x => x.GradeYearID == stuquery.FirstOrDefault().Years && x.CollegeID == stuquery.FirstOrDefault().CollegeID);
  111. }
  112. else
  113. {
  114. return mrquery.Where(x => x.GradeYearID == stuquery.FirstOrDefault().Years);
  115. }
  116. }
  117. else
  118. {
  119. return null;
  120. }
  121. }
  122. //public
  123. }
  124. }