using System; using System.Collections.Generic; using System.Linq; using System.Text; using EMISOnline.DataLogic.CourseworkMgr; using EMISOnline.Entities; using Bowin.Common.Utility; using EMISOnline.ViewModel.Coursework; using Bowin.Common.Linq.Entity; namespace EMISOnline.CommonLogic.CourseworkServices { public class TeacherScoreServices : ITeacherScoreServices { public TeacherScoreDAL teacherScoreDAL { get; set; } public string SetStudentScore(List tsmodels) { try { var DataUnitWork = teacherScoreDAL.teacherScoreRepository.UnitOfWork; //ER_TeacherScore tsEntity =null; tsmodels.ForEach(tsmodel => { if (tsmodel.TeacherScoreID == Guid.Empty) { tsmodel.TeacherScoreID = Function.NewPKGuid(); DataUnitWork.Add(tsmodel); } else { var dbmodel = DataUnitWork.ER_TeacherScore.FirstOrDefault(w => w.TeacherScoreID == tsmodel.TeacherScoreID); if (dbmodel != null) { dbmodel.Score = tsmodel.Score; dbmodel.ModifyTime = tsmodel.ModifyTime; dbmodel.ModifyUserID = tsmodel.ModifyUserID; DataUnitWork.Update(dbmodel); } } }); DataUnitWork.Commit(); } catch(Exception ex) { return ex.Message; } return ""; } public IGridResultSet ConrseScoreList(int page, int rows, string CoursematerialName, string StudentName, Guid TeacherID, Guid SchoolyearID) { var UnitOfWork = teacherScoreDAL.teacherScoreRepository.UnitOfWork; var scsql=teacherScoreDAL.getStudentClassListbySChoolYear(TeacherID, SchoolyearID); var tssql = teacherScoreDAL.StudentScoreList(TeacherID, SchoolyearID); if (!string.IsNullOrEmpty(CoursematerialName)) { scsql = scsql.Where(w => w.CourseName.Contains(CoursematerialName)); } var Students = UnitOfWork.Sys_User.AsQueryable(); if (!string.IsNullOrEmpty(StudentName)) { Students = Students.Where(w => w.Name.Contains(StudentName)); } var sql = from sc in scsql join ts in tssql on new { CoursematerialID = (Guid?)sc.CoursematerialID, sc.UserID, sc.SchoolyearID } equals new { ts.CoursematerialID, ts.UserID, ts.SchoolyearID } into ets from dts in ets.DefaultIfEmpty() join stu in Students on sc.UserID equals stu.UserID join y in UnitOfWork.CF_Schoolyear on sc.SchoolyearID equals y.SchoolyearID join t in UnitOfWork.Sys_User on sc.TeacherID equals t.UserID select new TeacherScoreView() { StudentID=sc.UserID, TeacherScoreID=(Guid?)dts.TeacherScoreID, StudentCardNo=stu.LoginID, StudentName=stu.Name, CoursematerialID=sc.CoursematerialID, CourseName=sc.CourseName, yearCode=y.Code, SchoolyearID=sc.SchoolyearID, TeacherID=sc.TeacherID, TeacherName=t.Name, Score=dts.Score, ModifyTime=dts.ModifyTime }; return sql.OrderByDescending(o => o.ModifyTime).ToGridResultSet(page, rows); } } }