using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EMIS.ViewModel.SchedulingManage.SchedulingSettings;
using EMIS.Entities;
using System.Linq.Expressions;
using EMIS.DataLogic.Repositories;
using EMIS.ViewModel.CalendarManage;
using EMIS.ViewModel;
namespace EMIS.DataLogic.SchedulingManage.SchedulingSettings
{
public class CourseScheduleSettingDAL
{
public CoursematerialRepository coursematerialRepository { get; set; }
public DictionaryItemRepository dictionaryItemRepository { get; set; }
public CoursesTimeRepository coursesTimeRepository { get; set; }
public CourseScheduleSettingRepository courseScheduleSettingRepository { get; set; }
///
/// 查询课程可排时间设置
///
///
///
public IQueryable GetCourseScheduleSettingViewQueryable(Expression> exp)
{
var query = from a in coursematerialRepository.GetList(exp)
join b in dictionaryItemRepository.GetList(x => x.DictionaryCode == typeof(EMIS.ViewModel.CF_CourseLevel).Name)
on a.CourseLevelID equals b.Value
into gcl
from gCourseLevel in gcl.DefaultIfEmpty()
join c in dictionaryItemRepository.GetList(x => x.DictionaryCode == typeof(EMIS.ViewModel.CF_CourseScience).Name)
on a.CourseScienceID equals c.Value
into gcs
from gCourseScience in gcs.DefaultIfEmpty()
select new CourseScheduleSettingView
{
CoursematerialID = a.CoursematerialID,
CourseCode = a.CourseCode,
CourseName = a.CourseName,
CourseScienceName = gCourseScience.Name,
CourseLevelName = gCourseLevel.Name,
IsEnableName = a.IsEnable == false ? "否" : "是",
CreateUserID = a.CreateUserID,
CreateTime = a.CreateTime
};
return query;
}
///
/// 获取教师可排时间设置
///
///
///
public IQueryable GetArrangementViewQueryable(Guid? coursematerialID)
{
var query = from a in coursesTimeRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE)
join b in
courseScheduleSettingRepository.GetList(x => x.CoursematerialID == coursematerialID)
on a.CoursesTimeID equals b.CoursesTimeID
group a by new
{
CoursesTimeID = a.CoursesTimeID,
StartTimes = a.StartTimes,
EndTimes = a.EndTimes,
TimesSegment = a.TimesSegment,
StartHour = a.StartHour,
StartMinutes = a.StartMinutes,
EndHour = a.EndHour,
EndMinutes = a.EndMinutes,
CreateTime = a.CreateTime,
CreateUserID = a.CreateUserID,
MondayIsOnWork = a.ES_CourseScheduleSetting.Where(x => x.Weekday == (int)DayOfWeek.Monday && x.CoursematerialID == b.CoursematerialID).FirstOrDefault().IsOnWork,
TuesdayIsOnWork = a.ES_CourseScheduleSetting.Where(x => x.Weekday == (int)DayOfWeek.Tuesday && x.CoursematerialID == b.CoursematerialID).FirstOrDefault().IsOnWork,
WednesdayIsOnWork = a.ES_CourseScheduleSetting.Where(x => x.Weekday == (int)DayOfWeek.Wednesday && x.CoursematerialID == b.CoursematerialID).FirstOrDefault().IsOnWork,
ThursdayIsOnWork = a.ES_CourseScheduleSetting.Where(x => x.Weekday == (int)DayOfWeek.Thursday && x.CoursematerialID == b.CoursematerialID).FirstOrDefault().IsOnWork,
FridayIsOnWork = a.ES_CourseScheduleSetting.Where(x => x.Weekday == (int)DayOfWeek.Friday && x.CoursematerialID == b.CoursematerialID).FirstOrDefault().IsOnWork,
SaturdayIsOnWork = a.ES_CourseScheduleSetting.Where(x => x.Weekday == (int)DayOfWeek.Saturday && x.CoursematerialID == b.CoursematerialID).FirstOrDefault().IsOnWork,
SundayIsOnWork = a.ES_CourseScheduleSetting.Where(x => x.Weekday == (int)DayOfWeek.Sunday && x.CoursematerialID == b.CoursematerialID).FirstOrDefault().IsOnWork
} into g
select new ArrangementView
{
CoursesTimeID = g.Key.CoursesTimeID,
StartTimes = g.Key.StartTimes,
EndTimes = g.Key.EndTimes,
TimesSegment = g.Key.TimesSegment,
StartHour = g.Key.StartHour,
StartMinutes = g.Key.StartMinutes,
EndHour = g.Key.EndHour,
EndMinutes = g.Key.EndMinutes,
CreateTime = g.Key.CreateTime,
CreateUserID = g.Key.CreateUserID,
MondayIsOnWork = g.Key.MondayIsOnWork,
TuesdayIsOnWork = g.Key.TuesdayIsOnWork,
WednesdayIsOnWork = g.Key.WednesdayIsOnWork,
ThursdayIsOnWork = g.Key.ThursdayIsOnWork,
FridayIsOnWork = g.Key.FridayIsOnWork,
SaturdayIsOnWork = g.Key.SaturdayIsOnWork,
SundayIsOnWork = g.Key.SundayIsOnWork,
};
return query;
}
}
}