TeacherScoreServices.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMISOnline.DataLogic.CourseworkMgr;
  6. using EMISOnline.Entities;
  7. using Bowin.Common.Utility;
  8. using EMISOnline.ViewModel.Coursework;
  9. using Bowin.Common.Linq.Entity;
  10. namespace EMISOnline.CommonLogic.CourseworkServices
  11. {
  12. public class TeacherScoreServices : ITeacherScoreServices
  13. {
  14. public TeacherScoreDAL teacherScoreDAL { get; set; }
  15. public string SetStudentScore(List<ER_TeacherScore> tsmodels)
  16. {
  17. try
  18. {
  19. var DataUnitWork = teacherScoreDAL.teacherScoreRepository.UnitOfWork;
  20. //ER_TeacherScore tsEntity =null;
  21. tsmodels.ForEach(tsmodel =>
  22. {
  23. if (tsmodel.TeacherScoreID == Guid.Empty)
  24. {
  25. tsmodel.TeacherScoreID = Function.NewPKGuid();
  26. DataUnitWork.Add(tsmodel);
  27. }
  28. else
  29. {
  30. var dbmodel = DataUnitWork.ER_TeacherScore.FirstOrDefault(w => w.TeacherScoreID == tsmodel.TeacherScoreID);
  31. if (dbmodel != null)
  32. {
  33. dbmodel.Score = tsmodel.Score;
  34. dbmodel.ModifyTime = tsmodel.ModifyTime;
  35. dbmodel.ModifyUserID = tsmodel.ModifyUserID;
  36. DataUnitWork.Update(dbmodel);
  37. }
  38. }
  39. });
  40. DataUnitWork.Commit();
  41. }
  42. catch(Exception ex)
  43. {
  44. return ex.Message;
  45. }
  46. return "";
  47. }
  48. public IGridResultSet<TeacherScoreView> ConrseScoreList(int page, int rows, string CoursematerialName, string StudentName, Guid TeacherID, Guid SchoolyearID)
  49. {
  50. var UnitOfWork = teacherScoreDAL.teacherScoreRepository.UnitOfWork;
  51. var scsql=teacherScoreDAL.getStudentClassListbySChoolYear(TeacherID, SchoolyearID);
  52. var tssql = teacherScoreDAL.StudentScoreList(TeacherID, SchoolyearID);
  53. if (!string.IsNullOrEmpty(CoursematerialName))
  54. {
  55. scsql = scsql.Where(w => w.CourseName.Contains(CoursematerialName));
  56. }
  57. var Students = UnitOfWork.Sys_User.AsQueryable();
  58. if (!string.IsNullOrEmpty(StudentName))
  59. {
  60. Students = Students.Where(w => w.Name.Contains(StudentName));
  61. }
  62. var sql = from sc in scsql
  63. join ts in tssql on new { CoursematerialID = (Guid?)sc.CoursematerialID, sc.UserID, sc.SchoolyearID } equals new { ts.CoursematerialID, ts.UserID, ts.SchoolyearID } into ets
  64. from dts in ets.DefaultIfEmpty()
  65. join stu in Students on sc.UserID equals stu.UserID
  66. join y in UnitOfWork.CF_Schoolyear on sc.SchoolyearID equals y.SchoolyearID
  67. join t in UnitOfWork.Sys_User on sc.TeacherID equals t.UserID
  68. select new TeacherScoreView() {
  69. StudentID=sc.UserID,
  70. TeacherScoreID=(Guid?)dts.TeacherScoreID,
  71. StudentCardNo=stu.LoginID,
  72. StudentName=stu.Name,
  73. CoursematerialID=sc.CoursematerialID,
  74. CourseName=sc.CourseName,
  75. yearCode=y.Code,
  76. SchoolyearID=sc.SchoolyearID,
  77. TeacherID=sc.TeacherID,
  78. TeacherName=t.Name,
  79. Score=dts.Score,
  80. ModifyTime=dts.ModifyTime
  81. };
  82. return sql.OrderByDescending(o => o.ModifyTime).ToGridResultSet(page, rows);
  83. }
  84. }
  85. }