using System; using System.Collections.Generic; using System.Linq; using System.Text; using EMIS.DataLogic.Common.CalendarManage; using Bowin.Common.Linq.Entity; using EMIS.Entities; using EMIS.ViewModel; using System.Linq.Expressions; using EMIS.ViewModel.CalendarManage; namespace EMIS.CommonLogic.CalendarManage { public class ActivitieServices : BaseServices, IActivitieServices { public ActivitieDAL activitieDAL { get; set; } /// /// 查询固定活动信息 /// /// 查询条件实体 /// 活动类型 /// 时间段 /// 页码 /// 显示页数 /// public IGridResultSet GetActivitieViewGrid(ConfiguretView configuretView, int? activitiesType, int? timesSegment, int pageIndex, int pageSize) { var query = activitieDAL.GetActivitiesQueryable(x => true); if (activitiesType.HasValue && activitiesType!=-1) query = query.Where(x => x.ActivitiesType == activitiesType); if (timesSegment.HasValue && timesSegment != -1) query = query.Where(x => x.TimesSegment == timesSegment); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue) .OrderBy(x => x.ActivitiesTimeMonth).ThenBy(x => x.ActivitiesTimeDay).ThenBy(x => x.TimesSegment).ToGridResultSet(pageIndex, pageSize); return query.OrderBy(x => x.ActivitiesTimeMonth).ThenBy(x => x.ActivitiesTimeDay).ThenBy(x => x.TimesSegment).ToGridResultSet(pageIndex, pageSize); } /// /// 查询固定活动信息 /// /// 查询条件实体 /// 活动类型 /// 时间段 /// public List GetActivitieViewList(ConfiguretView configuretView, int? activitiesType, int? timesSegment) { var query = activitieDAL.GetActivitiesQueryable(x => true); if (activitiesType.HasValue && activitiesType != -1) query = query.Where(x => x.ActivitiesType == activitiesType); if (timesSegment.HasValue && timesSegment != -1) query = query.Where(x => x.TimesSegment == timesSegment); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue) .OrderBy(x => x.ActivitiesTimeMonth).ThenBy(x => x.ActivitiesTimeDay).ThenBy(x => x.TimesSegment).ToList(); return query.OrderBy(x => x.ActivitiesTimeMonth).ThenBy(x => x.ActivitiesTimeDay).ThenBy(x => x.TimesSegment).ToList(); } /// /// 获取固定活动信息 /// /// 主键ID /// public CF_ActivitiesSets GetActivitie(Guid? activitiesID) { //查询条件 Expression> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expression = (x => x.ActivitiesID == activitiesID); return activitieDAL.activitiesSetsRepository.GetSingle(expression); } /// /// 获取固定活动信息 /// /// 活动名称 /// public CF_ActivitiesSets GetActivitie(string Name) { //查询条件 Expression> expression = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); expression = (x => x.Name == Name); return activitieDAL.activitiesSetsRepository.GetSingle(expression); } /// /// 获取固定活动信息 /// /// 主键ID /// public ActivitieView GetActivitieView(Guid? activitiesID) { ActivitieView activitieView = new ActivitieView(); if (activitiesID.HasValue) activitieView = activitieDAL.GetActivitiesQueryable(x => true).Where(x => x.ActivitiesID == activitiesID).FirstOrDefault(); return activitieView; } /// /// 添加 /// /// 实体 /// public bool ActivitiesAdd(ActivitieView activitieView) { try { if (this.activitieDAL.activitiesSetsRepository .GetList(x => x.Name == activitieView.Name&&x.ActivitiesTimeMonth==activitieView.ActivitiesTimeMonth && x.ActivitiesTimeDay == activitieView.ActivitiesTimeDay && x.TimesSegment == activitieView.TimesSegment).Count() > 0) { throw new Exception("已存在相同的数据,请重新输入!"); } CF_ActivitiesSets activitiesSets = new CF_ActivitiesSets(); activitiesSets.ActivitiesID = Guid.NewGuid(); activitiesSets.Name = activitieView.Name; activitiesSets.ActivitiesTimeMonth = activitieView.ActivitiesTimeMonth.Value; activitiesSets.ActivitiesTimeDay = activitieView.ActivitiesTimeDay.Value; activitiesSets.TimesSegment = activitieView.TimesSegment.Value; activitiesSets.ActivitiesContent = activitieView.ActivitiesContent; activitiesSets.ActivitiesType = activitieView.ActivitiesType; this.SetNewStatus(activitiesSets); UnitOfWork.Add(activitiesSets); UnitOfWork.Commit(); return true; } catch (Exception) { throw; } } /// /// 修改 /// /// 实体 /// public bool ActivitiesUpdate(ActivitieView activitieView) { try { CF_ActivitiesSets activitiesSets = GetActivitie(activitieView.ActivitiesID); if (activitiesSets == null) { throw new Exception("保存失败,未能找到相对应的数据!"); } activitiesSets.Name = activitieView.Name; activitiesSets.ActivitiesTimeMonth = activitieView.ActivitiesTimeMonth.Value; activitiesSets.ActivitiesTimeDay = activitieView.ActivitiesTimeDay.Value; activitiesSets.TimesSegment = activitieView.TimesSegment.Value; activitiesSets.ActivitiesContent = activitieView.ActivitiesContent; activitiesSets.ActivitiesType = activitieView.ActivitiesType; this.SetModifyStatus(activitiesSets); UnitOfWork.Commit(); return true; } catch (Exception) { throw; } } /// /// 删除 /// /// /// public bool ActivitiesDelete(List activitiesIDs) { try { UnitOfWork.Delete(x => activitiesIDs.Contains(x.ActivitiesID)); UnitOfWork.Commit(); return true; } catch (Exception) { throw; } } } }