123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- 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<ViewModel.SystemView.AnnouncementTypeView> GetAnnouncementTypeViewList
- (ViewModel.ConfiguretView configuretView, int pageIndex, int pageSize)
- {
- Expression<Func<Sys_AnnouncementType, bool>> 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<AnnouncementTypeView>(pageIndex, pageSize);
- return AnnouncementDAL.GetAnnouncementTypeView(exp).OrderBy(x => x.Name).ToGridResultSet<AnnouncementTypeView>(pageIndex, pageSize);
- }
- public IList<AnnouncementTypeView> GetUsableAnnouncementTypeViewList()
- {
- return AnnouncementDAL.GetAnnouncementTypeView(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).OrderBy(x => x.Name).ToList();
- }
- public Bowin.Common.Linq.Entity.IGridResultSet<ViewModel.SystemView.AnnouncementView> GetAnnouncementViewList
- (ViewModel.ConfiguretView configuretView, int pageIndex, int pageSize)
- {
- Expression<Func<Sys_Announcement, bool>> 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<AnnouncementView>(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<Guid?> 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<Sys_Role>();
- roleList.ForEach(x => announcementEntity.Sys_Role.Add(x));
- UnitOfWork.Commit();
- }
- public void DeleteType(IList<Guid?> announcementTypeID)
- {
- if (announcementTypeID.Count > 0)
- {
- UnitOfWork.Delete<Sys_AnnouncementType>(x => announcementTypeID.Contains(x.AnnouncementTypeID));
- }
- }
- public void Delete(IList<Guid?> 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<Sys_Role>();
- announcement.Sys_User = new HashSet<Sys_User>();
- }
- UnitOfWork.Remove<Sys_Announcement>(x => announcementID.Contains(x.AnnouncementID));
- UnitOfWork.Commit();
- }
- }
- /// <summary>
- /// 根据公告ID获取发布角色列表
- /// </summary>
- /// <param name="announcementID"></param>
- /// <returns></returns>
- public IList<RoleView> 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<AnnouncementView> 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<Func<Sys_Announcement, bool>> exp = (x => ((x.StartTime ?? sqlDateTimeMinValue) <= nowDateTime)
- && ((x.EndTime ?? sqlDateTimeMaxValue) >= nowDateTime));
- Expression<Func<Sys_Announcement, bool>> 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<Func<Sys_Announcement, bool>> 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);
- }
- }
- }
|