using System; using System.Collections.Generic; using System.Linq; using System.Text; using EMIS.ViewModel; using System.Linq.Expressions; using EMIS.Entities; using EMIS.DataLogic.Repositories; using EMIS.ViewModel.DQPSystem; using EMIS.ViewModel.CultureplanManage; namespace EMIS.DataLogic.DQPSystem { public class SOCTemplateDAL { public SOCTemplateDetailRepository SOCTemplateDetailRepository { get; set; } public SOCTemplateRepository SOCTemplateRepository { get; set; } public FacultymajorRepository facultymajorRepository { get; set; } public CoursematerialRepository coursematerialRepository { get; set; } public SpecialtyCourseRepository specialtyCourseRepository { get; set; } public DepartmentRepository departmentRepository { get; set; } public SOCTemplateDetailAttachmentRepository SOCTemplateDetailAttachmentRepository { get; set; } public DictionaryItemRepository dictionaryItemRepository { get; set; } //public FacultymajorRepository facultymajorRepository { get; set; } public IQueryable GetFileUploadViewQueryable(Expression> exp) { var sql = (from detail in SOCTemplateDetailRepository.GetList(exp) from attachment in detail.DQP_SOCTemplateDetailAttachment select new FileUploadView { FileID = attachment.SOCTemplateDetailAttachmentID, FormID = attachment.SOCTemplateItemID, FileUrl = attachment.Url, FileName = attachment.Name }); return sql; } public IQueryable GetSOCTemplateViewQueryable(Expression> exp, Expression> facexp) { var query = from templ in SOCTemplateRepository.GetList(exp) join dep in departmentRepository.Entities on templ.DepartmentID equals dep.DepartmentID join fac in facultymajorRepository.GetList(facexp) on templ.FacultymajorID equals fac.FacultymajorID into dfac from facde in dfac.DefaultIfEmpty() join cou in coursematerialRepository.Entities on templ.CoursematerialID equals cou.CoursematerialID //join spc in specialtyCourseRepository.Entities //on new { templ.CoursematerialID, templ.DepartmentID } equals new { spc.CoursematerialID, spc.DepartmentID } select new SOCTemplateView { SOCTemplateID = templ.SOCTemplateID, StandardID = facde.StandardID, FacultymajorID = facde.FacultymajorID, FacultymajorName = facde.Name, EducationID = facde.EducationID, LearningformID = facde.LearningformID, LearnSystem = facde.LearnSystem, CoursematerialID = templ.CoursematerialID, CourseCode = cou.CourseCode, CourseName = cou.CourseName, Credit = templ.Credit, SchoolyearNumID = templ.SchoolyearNumID, SchoolcodeID = templ.SchoolcodeID, DepartmentID = templ.DepartmentID, DepartmentCode = dep.No, IsEnable = templ.RecordStatus == 1 ? true : false, DepartmentName = dep.Name, RecordStatus = templ.RecordStatus, SOCCount = templ.DQP_SOCTemplateDetail.Count, HandleModeID = templ.HandleModeID, OptionalCourseTypeID = templ.OptionalCourseTypeID }; return query; } public IQueryable GetSOCTemplateDetailViewByIDQueryable(Expression> exp) { var query = from detail in SOCTemplateDetailRepository.GetList(exp) //join att in SOCTemplateDetailAttachmentRepository.Entities //on detail.SOCTemplateItemID equals att.SOCTemplateItemID //into deatt //from gatt in deatt.DefaultIfEmpty() select new SOCTemplateDetailView { SOCTemplateItemID = detail.SOCTemplateItemID, SOCTemplateID = detail.SOCTemplateID, Name = detail.Name, Credit = detail.Credit, Weight = detail.Weight, Description = detail.Description, AttachmentList = detail.DQP_SOCTemplateDetailAttachment, IsGroup = detail.IsGroup, }; return query; } public IQueryable GetSpecialtyCourseViewQueryable(Expression> exp, Expression> facexp) { var query = from a in specialtyCourseRepository.GetList(exp) join fac in facultymajorRepository.GetList(facexp) on new { a.CF_Department.CollegeID, a.CF_Specialty.StandardID } equals new { fac.CollegeID, fac.StandardID } join d in dictionaryItemRepository.Entities.Where(x => x.DictionaryCode == typeof(CF_Standard).Name) on a.CF_Specialty.StandardID equals d.Value select new SpecialtyCourseView { SpecialtyCourseID = a.SpecialtyCourseID, FacultymajorID = fac.FacultymajorID, DepartmentID = a.DepartmentID, DepartmentCode = a.CF_Department.No, DepartmentName = a.CF_Department.Name, CourseStructureID = a.CourseStructureID, CourseCategoryID = a.CourseCategoryID, CourseTypeID = a.CourseTypeID, CourseQualityID = a.CourseQualityID, PracticeTypeID = a.PracticeTypeID, ExaminationModeID = a.ExaminationModeID, TeachinglanguageID = a.TeachinglanguageID, SchoolyearNumID = (a.StarttermID % 2) == 0 ? (a.StarttermID / 2) : (a.StarttermID / 2) + 1, SchoolcodeID = (a.StarttermID % 2) == 0 ? 1 : 2, StarttermID = a.StarttermID, CourseFineID = a.CourseFineID, IsSpecialtycore = a.IsSpecialtycore ?? true, IsCooperation = a.IsCooperation ?? true, IsRequired = a.IsRequired ?? true, IsElective = a.IsElective ?? true, IsNetworkCourse = a.IsNetworkCourse ?? true, IsMainCourse = a.IsMainCourse ?? true, IsEnable = a.IsEnable ?? true, Credit = a.EM_SpecialtyCourseTeachingSetting.Credit ?? 0, TheoryCourse = a.EM_SpecialtyCourseTeachingSetting.TheoryCourse, Practicehours = a.EM_SpecialtyCourseTeachingSetting.Practicehours, Trialhours = a.EM_SpecialtyCourseTeachingSetting.Trialhours, Totalhours = (a.EM_SpecialtyCourseTeachingSetting.TheoryCourse + a.EM_SpecialtyCourseTeachingSetting.Practicehours), WeeklyNum = a.EM_SpecialtyCourseTeachingSetting.WeeklyNum, TheoryWeeklyNum = a.EM_SpecialtyCourseTeachingSetting.TheoryWeeklyNum, PracticeWeeklyNum = a.EM_SpecialtyCourseTeachingSetting.PracticeWeeklyNum, TrialWeeklyNum = a.EM_SpecialtyCourseTeachingSetting.TrialWeeklyNum, SchoolweeksNum = (a.EM_SpecialtyCourseTeachingSetting.TheoryWeeklyNum + a.EM_SpecialtyCourseTeachingSetting.PracticeWeeklyNum), StartWeeklyNum = a.EM_SpecialtyCourseTeachingSetting.StartWeeklyNum, EndWeeklyNum = a.EM_SpecialtyCourseTeachingSetting.EndWeeklyNum, SpecialtyID = a.CF_Specialty.SpecialtyID, StandardID = a.CF_Specialty.StandardID, LearnSystem = a.CF_Specialty.LearnSystem, EducationID = a.CF_Specialty.EducationID, LearningformID = a.CF_Specialty.LearningformID, CoursematerialID = a.EM_Coursematerial.CoursematerialID, CourseCode = a.EM_Coursematerial.CourseCode, CourseName = a.EM_Coursematerial.CourseName, WeeklyHours = a.EM_SpecialtyCourseTeachingSetting.WeeklyHours, ResultTypeID = a.ResultTypeID, CreateTime = a.CreateTime, CreateUserID = a.CreateUserID }; return query; } } }