using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EMIS.DataLogic.Repositories;
using EMIS.ViewModel.SchedulingManage.SchedulingSettings;
using EMIS.Entities;
using System.Linq.Expressions;
using EMIS.ViewModel.CalendarManage;
using EMIS.ViewModel;
namespace EMIS.DataLogic.SchedulingManage.SchedulingSettings
{
public class TeacherScheduleSettingDAL
{
public TeacherScheduleSettingRepository teacherScheduleSettingRepository { get; set; }
public StaffRepository staffRepository { get; set; }
public DictionaryItemRepository dictionaryItemRepository { get; set; }
public CoursesTimeRepository coursesTimeRepository { get; set; }
///
/// 获取已经教师可排时间设置
///
///
///
public IQueryable GetTeacherScheduleSettingViewQueryable(Expression> exp)
{
var query = from a in staffRepository.GetList(exp)
join c in dictionaryItemRepository.GetList(x => x.DictionaryCode == typeof(EMIS.ViewModel.CF_TeacherType).Name)
on a.TeacherTypeID equals c.Value into gtt
from gTeacherType in gtt.DefaultIfEmpty()
join d in dictionaryItemRepository.GetList(x => x.DictionaryCode == typeof(EMIS.ViewModel.CF_IncumbencyState).Name)
on a.IncumbencyState equals d.Value into gis
from gIncumbencyState in gis.DefaultIfEmpty()
join e in dictionaryItemRepository.GetList(x => x.DictionaryCode == typeof(EMIS.ViewModel.CF_Title).Name)
on a.TitleID equals e.Value into gt
from gTitle in gt.DefaultIfEmpty()
select new TeacherScheduleSettingView
{
UserID = a.UserID,
StaffCode = a.Sys_User.LoginID,
StaffName = a.Sys_User.Name,
TeacherTypeName = gTeacherType.Name,
IncumbencyStateName = gIncumbencyState.Name,
TitleName = gTitle.Name,
CollegeName = a.CF_College.Name,
CreateUserID = a.CreateUserID,
CreateTime = a.CreateTime
};
return query;
}
///
/// 获取教师可排时间设置
///
///
///
public IQueryable GetArrangementViewQueryable(Guid? userID)
{
var query = from a in coursesTimeRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE)
join b in
teacherScheduleSettingRepository.GetList(x => x.UserID == userID)
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_TeacherScheduleSetting.Where(x => x.Weekday == (int)DayOfWeek.Monday && x.UserID == b.UserID).FirstOrDefault().IsOnWork,
TuesdayIsOnWork = a.ES_TeacherScheduleSetting.Where(x => x.Weekday == (int)DayOfWeek.Tuesday && x.UserID == b.UserID).FirstOrDefault().IsOnWork,
WednesdayIsOnWork = a.ES_TeacherScheduleSetting.Where(x => x.Weekday == (int)DayOfWeek.Wednesday && x.UserID == b.UserID).FirstOrDefault().IsOnWork,
ThursdayIsOnWork = a.ES_TeacherScheduleSetting.Where(x => x.Weekday == (int)DayOfWeek.Thursday && x.UserID == b.UserID).FirstOrDefault().IsOnWork,
FridayIsOnWork = a.ES_TeacherScheduleSetting.Where(x => x.Weekday == (int)DayOfWeek.Friday && x.UserID == b.UserID).FirstOrDefault().IsOnWork,
SaturdayIsOnWork = a.ES_TeacherScheduleSetting.Where(x => x.Weekday == (int)DayOfWeek.Saturday && x.UserID == b.UserID).FirstOrDefault().IsOnWork,
SundayIsOnWork = a.ES_TeacherScheduleSetting.Where(x => x.Weekday == (int)DayOfWeek.Sunday && x.UserID == b.UserID).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;
}
}
}