using System; using System.Collections.Generic; using System.Linq; using System.Text; using EMIS.DataLogic.Repositories; using EMIS.ViewModel.SystemView; using System.Linq.Expressions; using EMIS.Entities; namespace EMIS.DataLogic.SystemDAL { public class AnnouncementDAL { public AnnouncementTypeRepository AnnouncementTypeRepository { get; set; } public AnnouncementRepository AnnouncementRepository { get; set; } public UserRepository UserRepository { get; set; } public IQueryable GetAnnouncementTypeView(Expression> typeExpression) { var q = (from at in AnnouncementTypeRepository.GetList(typeExpression) orderby at.No select new AnnouncementTypeView { AnnouncementTypeID = at.AnnouncementTypeID, No = at.No, Name = at.Name, Description = at.Description, RecordStatus = at.RecordStatus, CreateUserID = at.CreateUserID, CreateTime = at.CreateTime, ModifyUserID = at.ModifyUserID, ModifyTime = at.ModifyTime }); return q; } public IQueryable GetAnnouncementView(Expression> expression) { var q = (from a in AnnouncementRepository.GetList(expression) join cu in UserRepository.GetList(x => x.CF_Staff != null) on a.CreateUserID equals cu.UserID into dcu from ecu in dcu.DefaultIfEmpty() join mu in UserRepository.GetList(x => x.CF_Staff != null) on a.ModifyUserID equals mu.UserID into dmu from emu in dmu.DefaultIfEmpty() orderby a.CreateTime descending select new AnnouncementView { AnnouncementID = a.AnnouncementID, AnnouncementTypeID = a.AnnouncementTypeID, AnnouncementTypeDesc = a.Sys_AnnouncementType.Name, Title = a.Title, Content = a.Content, StartTime = a.StartTime, EndTime = a.EndTime, RecordStatus = a.RecordStatus, CreateUserID = a.CreateUserID, CreateUserName = ecu.Name, CreateTime = a.CreateTime, CreateDepartmentID = ecu.CF_Staff.DepartmentID, CreateDepartmentName = ecu.CF_Staff.CF_Department.Name, ModifyUserID = a.ModifyUserID, ModifyUserName = emu.Name, ModifyTime = a.ModifyTime, IsTop = a.IsTop, IsTopEdit = a.IsTop == null ? false : (a.IsTop.Value ? true : false), OrderByNum = a.IsTop == null ? 2 : (a.IsTop.Value ? 0 : 1), }); return q; } } }