LessonRecordDAL.cs 4.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Bowin.Common.Linq;
  6. using EMIS.ViewModel.SupervisionManage;
  7. using EMIS.DataLogic.Repositories;
  8. using System.Linq.Expressions;
  9. using EMIS.Entities;
  10. using EMIS.ViewModel;
  11. namespace EMIS.DataLogic.SupervisionManage
  12. {
  13. public class LessonRecordDAL
  14. {
  15. public LessonRecordRepository LessonRecordRepository { get; set; }
  16. public LessonRecordAttachmentRepository LessonRecordAttachmentRepository { get; set; }
  17. public SupervisionCollegeRepository SupervisionCollegeRepository { get; set; }
  18. public ClassmajorRepository ClassmajorRepository { get; set; }
  19. public CoursematerialRepository CoursematerialRepository { get; set; }
  20. public CoursesTimeRepository CoursesTimeRepository { get; set; }
  21. public UserRepository UserRepository { get; set; }
  22. public StaffRepository StaffRepository { get; set; }
  23. public SchoolyearRepository SchoolyearRepository { get; set; }
  24. public IQueryable<LessonRecordView> GetLessonRecordViewQueryable(Expression<Func<SUP_LessonRecord, bool>> exp,
  25. Expression<Func<CF_Staff, bool>> supervisorExp)
  26. {
  27. var sql = (from record in LessonRecordRepository.GetList(exp)
  28. from schoolyear in SchoolyearRepository.Entities.Where(x => x.SchoolyearID == record.SchoolyearID)
  29. from college in SupervisionCollegeRepository.Entities.Where(x => x.SupervisionCollegeID == record.SupervisionCollegeID)
  30. from user in UserRepository.Entities.Where(x => x.UserID == record.UserID)
  31. from classmajor in ClassmajorRepository.Entities.Where(x => x.ClassmajorID == record.ClassmajorID)
  32. .DefaultIfEmpty()
  33. from course in CoursematerialRepository.Entities.Where(x => x.CoursematerialID == record.CoursematerialID)
  34. from time in CoursesTimeRepository.Entities.Where(x => x.CoursesTimeID == record.CoursesTimeID)
  35. from creator in UserRepository.Entities.Where(x => x.UserID == record.CreateUserID)
  36. from staff in StaffRepository.Entities.Where(x => x.UserID == creator.UserID).DefaultIfEmpty().Where(supervisorExp)
  37. select new LessonRecordView
  38. {
  39. LessonRecordID = record.LessonRecordID,
  40. SchoolyearID = record.SchoolyearID,
  41. SchoolyearCode = schoolyear.Code,
  42. LessonDate = record.LessonDate,
  43. Location = record.Location,
  44. SupervisionCollegeID = record.SupervisionCollegeID,
  45. SupervisionCollegeName = college.Name,
  46. UserID = record.UserID,
  47. UserName = user.Name,
  48. ClassmajorID = record.ClassmajorID,
  49. ClassmajorName = classmajor.Name,
  50. CoursematerialID = record.CoursematerialID,
  51. CourseName = course.CourseName,
  52. Weekday = record.Weekday,
  53. CoursesTimeID = record.CoursesTimeID,
  54. StartTimes = time.StartTimes,
  55. EndTimes = time.EndTimes,
  56. TotalScore = record.TotalScore,
  57. Content = record.Content,
  58. Record = record.Record,
  59. CreateUserID = record.CreateUserID,
  60. CreateUserName = creator.Name,
  61. CollegeID = staff.CollegeID
  62. });
  63. return sql;
  64. }
  65. public IQueryable<FileUploadView> GetLessonRecordAttachmentQueryable(Expression<Func<SUP_LessonRecord, bool>> exp)
  66. {
  67. var tableName = typeof(SUP_LessonRecordAttachment).Name;
  68. var sql = (from record in LessonRecordRepository.GetList(exp)
  69. from attachment in LessonRecordAttachmentRepository.Entities.Where(x => x.LessonRecordID == record.LessonRecordID)
  70. select new FileUploadView
  71. {
  72. FileID = attachment.LessonRecordAttachmentID,
  73. TableName = tableName,
  74. FormID = attachment.LessonRecordID,
  75. FileName = attachment.Name,
  76. FileUrl = attachment.Url
  77. });
  78. return sql;
  79. }
  80. }
  81. }