using System; using System.Collections.Generic; using System.Linq; using System.Text; using EMIS.DataLogic.Repositories; using EMIS.ViewModel.CalendarManage; using System.Linq.Expressions; using EMIS.Entities; using EMIS.ViewModel; namespace EMIS.DataLogic.Common.CalendarManage { public class ArrangementDAL { public ArrangementsRepository ArrangementsRepository { get; set; } public CoursesTimeRepository coursesTimeRepository { get; set; } public DictionaryItemRepository dictionaryItemRepository { get; set; } public IQueryable GetArrangementView(Expression> exp) { var sql = (from a in ArrangementsRepository.GetList(exp) select new ArrangementView { ArrangementsID = a.ArrangementsID, CoursesTimeID = a.CoursesTimeID, StartTimes = a.EM_CoursesTime.StartTimes, EndTimes = a.EM_CoursesTime.EndTimes, TimesSegment = a.EM_CoursesTime.TimesSegment, StartHour = a.EM_CoursesTime.StartHour, EndHour = a.EM_CoursesTime.EndHour, StartMinutes = a.EM_CoursesTime.StartMinutes, EndMinutes = a.EM_CoursesTime.EndMinutes, Weekday = a.Weekday, IsOnWork = a.IsOnWork, RecordStatus = a.RecordStatus, CreateTime = a.CreateTime, CreateUserID = a.CreateUserID, ModifyTime = a.ModifyTime, ModifyUserID = a.ModifyUserID }); return sql; } public IQueryable GetArrangementViewQueryable() { var query = from a in coursesTimeRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE) select new ArrangementView { 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.CF_Arrangements.Where(x => x.Weekday == (int)DayOfWeek.Monday).FirstOrDefault() == null ? false : a.CF_Arrangements.Where(x => x.Weekday == (int)DayOfWeek.Monday).FirstOrDefault().IsOnWork, TuesdayIsOnWork = a.CF_Arrangements.Where(x => x.Weekday == (int)DayOfWeek.Tuesday).FirstOrDefault() == null ? false : a.CF_Arrangements.Where(x => x.Weekday == (int)DayOfWeek.Tuesday).FirstOrDefault().IsOnWork, WednesdayIsOnWork = a.CF_Arrangements.Where(x => x.Weekday == (int)DayOfWeek.Wednesday).FirstOrDefault() == null ? false : a.CF_Arrangements.Where(x => x.Weekday == (int)DayOfWeek.Wednesday).FirstOrDefault().IsOnWork, ThursdayIsOnWork = a.CF_Arrangements.Where(x => x.Weekday == (int)DayOfWeek.Thursday).FirstOrDefault() == null ? false : a.CF_Arrangements.Where(x => x.Weekday == (int)DayOfWeek.Thursday).FirstOrDefault().IsOnWork, FridayIsOnWork = a.CF_Arrangements.Where(x => x.Weekday == (int)DayOfWeek.Friday).FirstOrDefault() == null ? false : a.CF_Arrangements.Where(x => x.Weekday == (int)DayOfWeek.Friday).FirstOrDefault().IsOnWork, SaturdayIsOnWork = a.CF_Arrangements.Where(x => x.Weekday == (int)DayOfWeek.Saturday).FirstOrDefault() == null ? false : a.CF_Arrangements.Where(x => x.Weekday == (int)DayOfWeek.Saturday).FirstOrDefault().IsOnWork, SundayIsOnWork = a.CF_Arrangements.Where(x => x.Weekday == (int)DayOfWeek.Sunday).FirstOrDefault() == null ? false : a.CF_Arrangements.Where(x => x.Weekday == (int)DayOfWeek.Sunday).FirstOrDefault().IsOnWork }; return query; } } }