SOCScoreDAL.cs 5.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.ViewModel.DQPSystem;
  6. using System.Linq.Expressions;
  7. using EMIS.Entities;
  8. using EMIS.DataLogic.Repositories;
  9. namespace EMIS.DataLogic.DQPSystem
  10. {
  11. public class SOCScoreDAL
  12. {
  13. public SOCDetailStudentScoreRepository SOCDetailStudentScoreRepository { get; set; }
  14. public SOCDetailRepository SOCDetailRepository { get; set; }
  15. public SOCRepository SOCRepository { get; set; }
  16. public SchoolyearRepository SchoolyearRepository { get; set; }
  17. public CoursematerialRepository CoursematerialRepository { get; set; }
  18. public CollegeRepository CollegeRepository { get; set; }
  19. public FacultymajorRepository FacultymajorRepository { get; set; }
  20. public GrademajorRepository GrademajorRepository { get; set; }
  21. public ClassmajorRepository ClassmajorRepository { get; set; }
  22. public UserRepository UserRepository { get; set; }
  23. public IQueryable<SOCCourseScoreView> GetSOCCourseScoreViewQueryable(Expression<Func<DQP_SOC, bool>> socExp,
  24. Expression<Func<DQP_SOCDetail, bool>> detailExp,
  25. Expression<Func<CF_Facultymajor, bool>> facultyExp,
  26. Expression<Func<CF_Grademajor, bool>> gradeExp,
  27. Expression<Func<CF_Classmajor, bool>> classExp)
  28. {
  29. var sql = (from soc in SOCRepository.GetList(socExp)
  30. join schoolyear in SchoolyearRepository.Entities on soc.SchoolyearID equals schoolyear.SchoolyearID
  31. join course in CoursematerialRepository.Entities on soc.CoursematerialID equals course.CoursematerialID
  32. join detail in SOCDetailRepository.GetList(detailExp) on soc.SOCID equals detail.SOCID
  33. from student in soc.CF_Student
  34. join user in UserRepository.Entities on student.UserID equals user.UserID
  35. join classmajor in ClassmajorRepository.Entities.Where(classExp) on student.ClassmajorID equals classmajor.ClassmajorID
  36. join grade in GrademajorRepository.Entities.Where(gradeExp) on classmajor.GrademajorID equals grade.GrademajorID
  37. join faculty in FacultymajorRepository.Entities.Where(facultyExp) on grade.FacultymajorID equals faculty.FacultymajorID
  38. join college in CollegeRepository.Entities on faculty.CollegeID equals college.CollegeID
  39. from score in SOCDetailStudentScoreRepository.Entities
  40. .Where(x => x.SOCDetailID == detail.SOCDetailID && x.UserID == student.UserID).DefaultIfEmpty()
  41. group new { Detail = detail, Score = score } by new
  42. {
  43. soc.SOCID,
  44. soc.SchoolyearID,
  45. SchoolyearCode = schoolyear.Code,
  46. course.CoursematerialID,
  47. course.CourseCode,
  48. course.CourseName,
  49. TotalCredit = soc.Credit,
  50. college.CollegeID,
  51. CollegeNo = college.No,
  52. CollegeName = college.Name,
  53. student.ClassmajorID,
  54. ClassmajorNo = classmajor.No,
  55. ClassmajorName = classmajor.Name,
  56. Gradeyear = grade.GradeID,
  57. faculty.StandardID,
  58. student.UserID,
  59. user.LoginID,
  60. user.Name
  61. } into g
  62. select new SOCCourseScoreView
  63. {
  64. SOCID = g.Key.SOCID,
  65. SchoolyearID = g.Key.SchoolyearID,
  66. SchoolyearCode = g.Key.SchoolyearCode,
  67. CoursematerialID = g.Key.CoursematerialID,
  68. CourseCode = g.Key.CourseCode,
  69. CourseName = g.Key.CourseName,
  70. TotalCredit = g.Key.TotalCredit,
  71. CollegeID = g.Key.CollegeID,
  72. CollegeNo = g.Key.CollegeNo,
  73. Gradeyear = g.Key.Gradeyear,
  74. StandardID = g.Key.StandardID,
  75. CollegeName = g.Key.CollegeName,
  76. ClassmajorID = g.Key.ClassmajorID,
  77. ClassmajorNo = g.Key.ClassmajorNo,
  78. ClassmajorName = g.Key.ClassmajorName,
  79. UserID = g.Key.UserID,
  80. LoginID = g.Key.LoginID,
  81. Name = g.Key.Name,
  82. TotalScore = g.Sum(x => x.Score.Score) == null ? (decimal?)null : g.Sum(x => (x.Score.Score ?? 0) * (x.Detail.Weight ?? 0) / 100),
  83. Credit = g.Sum(x => x.Score.Score) == null ? (decimal?)null : (g.Sum(x => (x.Score.Score ?? 0) * (x.Detail.Weight ?? 0) / 100) > 60 ? g.Key.TotalCredit : 0)
  84. });
  85. return sql;
  86. }
  87. }
  88. }