LessonRecordServices.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Linq.Expressions;
  5. using System.Text;
  6. using Bowin.Common.Linq;
  7. using Bowin.Common.Linq.Entity;
  8. using EMIS.DataLogic.SupervisionManage;
  9. using EMIS.ViewModel.SupervisionManage;
  10. using EMIS.ViewModel;
  11. using EMIS.Entities;
  12. using EMIS.CommonLogic.CalendarManage;
  13. using EMIS.CommonLogic.SystemServices;
  14. using System.Web;
  15. namespace EMIS.CommonLogic.SupervisionManage
  16. {
  17. public class LessonRecordServices : BaseServices, ILessonRecordServices, IFileUploadServices
  18. {
  19. public LessonRecordDAL LessonRecordDAL { get; set; }
  20. public Lazy<ISchoolYearServices> SchoolYearServices { get; set; }
  21. public IGridResultSet<LessonRecordView> GetLessonRecordViewGrid(ConfiguretView conditionView, Guid? schoolyearID, Guid? collegeID,
  22. Guid? supervisionCollegeID, DateTime? startDate, DateTime? endDate, int? pageIndex = null, int? pageSize = null)
  23. {
  24. Expression<Func<SUP_LessonRecord, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  25. Expression<Func<CF_Staff, bool>> supervisorExp = (x => true);
  26. if (schoolyearID.HasValue)
  27. {
  28. exp = exp.And(x => x.SchoolyearID == schoolyearID);
  29. }
  30. if (collegeID.HasValue)
  31. {
  32. supervisorExp = supervisorExp.And(x => x.CollegeID == collegeID);
  33. }
  34. if (supervisionCollegeID.HasValue)
  35. {
  36. exp = exp.And(x => x.SupervisionCollegeID == supervisionCollegeID);
  37. }
  38. if (startDate.HasValue)
  39. {
  40. exp = exp.And(x => x.LessonDate >= startDate);
  41. }
  42. if (endDate.HasValue)
  43. {
  44. var correctEndDate = endDate.Value.Date.AddDays(1);
  45. exp = exp.And(x => x.LessonDate < correctEndDate);
  46. }
  47. var query = LessonRecordDAL.GetLessonRecordViewQueryable(exp, supervisorExp);
  48. if (!string.IsNullOrEmpty(conditionView.ConditionValue))
  49. {
  50. query = query.DynamicWhere(conditionView.Attribute, conditionView.Condition, conditionView.ConditionValue);
  51. }
  52. query = this.GetQueryByDataRange(query).OrderByDescending(x => x.SchoolyearCode).ThenByDescending(x => x.LessonDate)
  53. .ThenBy(x => x.StartTimes);
  54. return query.ToGridResultSet(pageIndex, pageSize);
  55. }
  56. public List<LessonRecordView> GetLessonRecordViewList(ConfiguretView conditionView, Guid? schoolyearID, Guid? collegeID,
  57. Guid? supervisionCollegeID, DateTime? startDate, DateTime? endDate)
  58. {
  59. return GetLessonRecordViewGrid(conditionView, schoolyearID, collegeID, supervisionCollegeID, startDate, endDate).rows;
  60. }
  61. public LessonRecordView GetLessonRecordView(Guid lessonRecordID)
  62. {
  63. return LessonRecordDAL.GetLessonRecordViewQueryable(x => x.LessonRecordID == lessonRecordID, (x => true)).FirstOrDefault();
  64. }
  65. public void Save(LessonRecordView lessonRecordView, IList<FileUploadView> attachmentList)
  66. {
  67. var lessonRecord = new SUP_LessonRecord();
  68. if (lessonRecordView.LessonRecordID != Guid.Empty)
  69. {
  70. lessonRecord = this.LessonRecordDAL.LessonRecordRepository.GetSingle(x => x.LessonRecordID == lessonRecordView.LessonRecordID,
  71. (x => x.SUP_LessonRecordAttachment));
  72. this.SetModifyStatus(lessonRecord);
  73. }
  74. else
  75. {
  76. lessonRecord.LessonRecordID = Guid.NewGuid();
  77. //lessonRecord.SchoolyearID = SchoolYearServices.Value.GetCurrentSchoolYear().SchoolYearID;
  78. this.SetNewStatus(lessonRecord);
  79. this.UnitOfWork.Add(lessonRecord);
  80. }
  81. lessonRecord.SchoolyearID = lessonRecordView.SchoolyearID;
  82. lessonRecord.LessonDate = lessonRecordView.LessonDate;
  83. lessonRecord.Location = lessonRecordView.Location;
  84. lessonRecord.SupervisionCollegeID = lessonRecordView.SupervisionCollegeID;
  85. lessonRecord.UserID = lessonRecordView.UserID;
  86. lessonRecord.ClassmajorID = lessonRecordView.ClassmajorID;
  87. lessonRecord.CoursematerialID = lessonRecordView.CoursematerialID;
  88. lessonRecord.Weekday = lessonRecordView.Weekday;
  89. lessonRecord.CoursesTimeID = lessonRecordView.CoursesTimeID;
  90. lessonRecord.TotalScore = lessonRecordView.TotalScore;
  91. lessonRecord.Content = HttpUtility.HtmlDecode(lessonRecordView.Content);
  92. //lessonRecordView.Content.Replace("&lt;", "<").Replace("&gt", ">").Replace("&amp", "&").Replace("&quot", "\"").Replace("&apos", "'");
  93. //System.Text.RegularExpressions.Regex.Unescape(lessonRecordView.Content);
  94. lessonRecord.Record = HttpUtility.HtmlDecode(lessonRecordView.Record);
  95. //System.Text.RegularExpressions.Regex.Unescape(lessonRecordView.Record);
  96. lessonRecord.SUP_LessonRecordAttachment = new HashSet<SUP_LessonRecordAttachment>();
  97. if (attachmentList!=null)
  98. {
  99. attachmentList.ToList().ForEach(x =>
  100. {
  101. var attachment = new SUP_LessonRecordAttachment();
  102. attachment.LessonRecordAttachmentID = Guid.NewGuid();
  103. attachment.LessonRecordID = lessonRecord.LessonRecordID;
  104. attachment.Name = x.FileName;
  105. attachment.Url = x.FileUrl;
  106. this.SetNewStatus(attachment);
  107. UnitOfWork.Add(attachment);
  108. });
  109. }
  110. UnitOfWork.Commit();
  111. }
  112. public void Delete(IList<Guid?> lessonRecordIDList)
  113. {
  114. UnitOfWork.Delete<SUP_LessonRecordAttachment>(x => lessonRecordIDList.Contains(x.LessonRecordID));
  115. UnitOfWork.Delete<SUP_LessonRecord>(x => lessonRecordIDList.Contains(x.LessonRecordID));
  116. }
  117. public List<FileUploadView> GetFileList(Guid? formID)
  118. {
  119. return LessonRecordDAL.GetLessonRecordAttachmentQueryable(x => x.LessonRecordID == formID).ToList();
  120. }
  121. }
  122. }