using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Linq.Expressions; using System.Data.SqlTypes; using Bowin.Common.Linq; using Bowin.Common.Linq.Entity; using EMIS.DataLogic.SystemDAL; using EMIS.Entities; using EMIS.ViewModel.SystemView; using EMIS.ViewModel; using System.Web; namespace EMIS.CommonLogic.SystemServices { public class AnnouncementServices : BaseServices, IAnnouncementServices { public AnnouncementDAL AnnouncementDAL { get; set; } public RoleDAL RoleDAL { get; set; } public Bowin.Common.Linq.Entity.IGridResultSet GetAnnouncementTypeViewList (ViewModel.ConfiguretView configuretView, int pageIndex, int pageSize) { Expression> exp = (x => true); if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute)) return AnnouncementDAL.GetAnnouncementTypeView(exp).DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.Name) .ToGridResultSet(pageIndex, pageSize); return AnnouncementDAL.GetAnnouncementTypeView(exp).OrderBy(x => x.Name).ToGridResultSet(pageIndex, pageSize); } public IList GetUsableAnnouncementTypeViewList() { return AnnouncementDAL.GetAnnouncementTypeView(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).OrderBy(x => x.Name).ToList(); } public Bowin.Common.Linq.Entity.IGridResultSet GetAnnouncementViewList (ViewModel.ConfiguretView configuretView, int pageIndex, int pageSize) { Expression> exp = (x => true); var query = AnnouncementDAL.GetAnnouncementView(exp); if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); } return query.OrderByDescending(x => x.StartTime).ToGridResultSet(pageIndex, pageSize); } public ViewModel.SystemView.AnnouncementTypeView GetAnnouncementTypeViewInfo(Guid? announcementTypeID) { return AnnouncementDAL.GetAnnouncementTypeView(x => x.AnnouncementTypeID == announcementTypeID).FirstOrDefault(); } public ViewModel.SystemView.AnnouncementView GetAnnouncementViewInfo(Guid? announcementID) { return AnnouncementDAL.GetAnnouncementView(x => x.AnnouncementID == announcementID).FirstOrDefault(); } public void SaveType(ViewModel.SystemView.AnnouncementTypeView announcementType) { var announcementTypeEntity = AnnouncementDAL.AnnouncementTypeRepository.GetSingle (x => x.AnnouncementTypeID == announcementType.AnnouncementTypeID); if (announcementTypeEntity != null) { announcementTypeEntity.No = announcementType.No; announcementTypeEntity.Name = announcementType.Name; announcementTypeEntity.Description = announcementType.Description; this.SetModifyStatus(announcementTypeEntity); } else { announcementTypeEntity = new Sys_AnnouncementType(); announcementTypeEntity.AnnouncementTypeID = Guid.NewGuid(); announcementTypeEntity.No = announcementType.No; announcementTypeEntity.Name = announcementType.Name; announcementTypeEntity.Description = announcementType.Description; this.SetNewStatus(announcementTypeEntity); UnitOfWork.Add(announcementTypeEntity); } UnitOfWork.Commit(); } public void Save(ViewModel.SystemView.AnnouncementView announcement, IList roleIDList) { announcement.Content = HttpUtility.HtmlDecode(announcement.Content); var announcementEntity = AnnouncementDAL.AnnouncementRepository.GetSingle (x => x.AnnouncementID == announcement.AnnouncementID, (x => x.Sys_Role)); if (announcementEntity != null) { announcementEntity.AnnouncementTypeID = announcement.AnnouncementTypeID; announcementEntity.Title = announcement.Title; announcementEntity.Content = announcement.Content; announcementEntity.StartTime = announcement.StartTime; announcementEntity.EndTime = announcement.EndTime; this.SetModifyStatus(announcementEntity); } else { announcementEntity = new Sys_Announcement(); announcementEntity.AnnouncementID = Guid.NewGuid(); announcementEntity.AnnouncementTypeID = announcement.AnnouncementTypeID; announcementEntity.Title = announcement.Title; announcementEntity.Content = announcement.Content; announcementEntity.StartTime = announcement.StartTime; announcementEntity.EndTime = announcement.EndTime; this.SetNewStatus(announcementEntity); UnitOfWork.Add(announcementEntity); } var roleList = RoleDAL.RoleRepository.GetList(x => roleIDList.Contains(x.RoleID)).ToList(); announcementEntity.Sys_Role = new HashSet(); roleList.ForEach(x => announcementEntity.Sys_Role.Add(x)); UnitOfWork.Commit(); } public void DeleteType(IList announcementTypeID) { if (announcementTypeID.Count > 0) { UnitOfWork.Delete(x => announcementTypeID.Contains(x.AnnouncementTypeID)); } } public void Delete(IList announcementID) { if (announcementID.Count > 0) { var announcementList = AnnouncementDAL.AnnouncementRepository.GetList(x => announcementID.Contains(x.AnnouncementID), (x => x.Sys_Role), (x => x.Sys_User)); foreach (var announcement in announcementList) { announcement.Sys_Role = new HashSet(); announcement.Sys_User = new HashSet(); } UnitOfWork.Remove(x => announcementID.Contains(x.AnnouncementID)); UnitOfWork.Commit(); } } /// /// 根据公告ID获取发布角色列表 /// /// /// public IList GetAnnouncementRoleViewList(Guid announcementID) { return RoleDAL.GetRoleView(x => x.Sys_Announcement.Any(w => w.AnnouncementID == announcementID)) .OrderBy(x=>x.OrderNo).ThenBy(x=>x.TypeID).ToList(); } public IGridResultSet GetUserAnnouncementView(Guid userID, int pageIndex, int pageSize) { var nowDateTime = DateTime.Now; var sqlDateTimeMinValue = SqlDateTime.MinValue.Value; var sqlDateTimeMaxValue = SqlDateTime.MaxValue.Value; //var socAnnouncementType = AnnouncementDAL.AnnouncementTypeRepository.GetList(); Expression> exp = (x => ((x.StartTime ?? sqlDateTimeMinValue) <= nowDateTime) && ((x.EndTime ?? sqlDateTimeMaxValue) >= nowDateTime)); Expression> exp1 = exp.And(x => x.Sys_Role.Any(w => w.Sys_User.Any(u => u.UserID == userID)) || x.Sys_User.Any(y => y.UserID ==userID)); Expression> exp2 = exp.And(x => x.Sys_Role.Count == 0 && x.Sys_User.Count == 0); return this.AnnouncementDAL.GetAnnouncementView(exp1).Concat(this.AnnouncementDAL.GetAnnouncementView(exp2)) .OrderByDescending(x => x.StartTime).ThenByDescending(x => x.CreateTime).ToGridResultSet(pageIndex, pageSize); } } }