using System; using System.Collections.Generic; using System.Linq; using System.Text; using Bowin.Common.Linq; using EMIS.ViewModel.SupervisionManage; using EMIS.DataLogic.Repositories; using System.Linq.Expressions; using EMIS.Entities; using EMIS.ViewModel; namespace EMIS.DataLogic.SupervisionManage { public class LessonRecordDAL { public LessonRecordRepository LessonRecordRepository { get; set; } public LessonRecordAttachmentRepository LessonRecordAttachmentRepository { get; set; } public SupervisionCollegeRepository SupervisionCollegeRepository { get; set; } public ClassmajorRepository ClassmajorRepository { get; set; } public CoursematerialRepository CoursematerialRepository { get; set; } public CoursesTimeRepository CoursesTimeRepository { get; set; } public UserRepository UserRepository { get; set; } public StaffRepository StaffRepository { get; set; } public SchoolyearRepository SchoolyearRepository { get; set; } public IQueryable GetLessonRecordViewQueryable(Expression> exp, Expression> supervisorExp) { var sql = (from record in LessonRecordRepository.GetList(exp) from schoolyear in SchoolyearRepository.Entities.Where(x => x.SchoolyearID == record.SchoolyearID) from college in SupervisionCollegeRepository.Entities.Where(x => x.SupervisionCollegeID == record.SupervisionCollegeID) from user in UserRepository.Entities.Where(x => x.UserID == record.UserID) from classmajor in ClassmajorRepository.Entities.Where(x => x.ClassmajorID == record.ClassmajorID) .DefaultIfEmpty() from course in CoursematerialRepository.Entities.Where(x => x.CoursematerialID == record.CoursematerialID) from time in CoursesTimeRepository.Entities.Where(x => x.CoursesTimeID == record.CoursesTimeID) from creator in UserRepository.Entities.Where(x => x.UserID == record.CreateUserID) from staff in StaffRepository.Entities.Where(x => x.UserID == creator.UserID).DefaultIfEmpty().Where(supervisorExp) select new LessonRecordView { LessonRecordID = record.LessonRecordID, SchoolyearID = record.SchoolyearID, SchoolyearCode = schoolyear.Code, LessonDate = record.LessonDate, Location = record.Location, SupervisionCollegeID = record.SupervisionCollegeID, SupervisionCollegeName = college.Name, UserID = record.UserID, UserName = user.Name, ClassmajorID = record.ClassmajorID, ClassmajorName = classmajor.Name, CoursematerialID = record.CoursematerialID, CourseName = course.CourseName, Weekday = record.Weekday, CoursesTimeID = record.CoursesTimeID, StartTimes = time.StartTimes, EndTimes = time.EndTimes, TotalScore = record.TotalScore, Content = record.Content, Record = record.Record, CreateUserID = record.CreateUserID, CreateUserName = creator.Name, CollegeID = staff.CollegeID }); return sql; } public IQueryable GetLessonRecordAttachmentQueryable(Expression> exp) { var tableName = typeof(SUP_LessonRecordAttachment).Name; var sql = (from record in LessonRecordRepository.GetList(exp) from attachment in LessonRecordAttachmentRepository.Entities.Where(x => x.LessonRecordID == record.LessonRecordID) select new FileUploadView { FileID = attachment.LessonRecordAttachmentID, TableName = tableName, FormID = attachment.LessonRecordID, FileName = attachment.Name, FileUrl = attachment.Url }); return sql; } } }