123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Linq.Expressions;
- using Bowin.Common.Linq;
- using Bowin.Common.Linq.Entity;
- using EMIS.Entities;
- using EMIS.DataLogic.ExaminationManage;
- using EMIS.ViewModel;
- using EMIS.ViewModel.ExaminationManage;
- using Bowin.Common.Exceptions;
- namespace EMIS.CommonLogic.ExaminationManage
- {
- public class TimeSegmentServices : BaseServices, ITimeSegmentServices
- {
- public TimeSegmentDAL TimeSegmentDAL { get; set; }
- public IGridResultSet<TimeSegmentView> GetTimeSegmentViewList(ConfiguretView timeSegmentConditionView, int pageIndex, int pageSize)
- {
- Expression<Func<EX_TimeSegment, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- var query = TimeSegmentDAL.GetTimeSegmentView(exp);
- if (!string.IsNullOrEmpty(timeSegmentConditionView.ConditionValue) && !string.IsNullOrEmpty(timeSegmentConditionView.Attribute))
- query = query.DynamicWhere(timeSegmentConditionView.Attribute, timeSegmentConditionView.Condition, timeSegmentConditionView.ConditionValue);
- query = query.OrderByDescending(x => x.ExaminationDate).ThenByDescending(x => x.StartTime).ThenByDescending(x => x.EndTime);
- return query.ToGridResultSet<TimeSegmentView>(pageIndex, pageSize);
- }
- public List<TimeSegmentView> GetTimeSegmentViewList(bool? isForResit = null)
- {
- Expression<Func<EX_TimeSegment, bool>> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (isForResit.HasValue)
- {
- exp = exp.And(x => x.IsForResit == isForResit);
- }
- var query = TimeSegmentDAL.GetTimeSegmentView(exp);
- query = query.OrderByDescending(x => x.ExaminationDate).OrderByDescending(x => x.StartTime).OrderByDescending(x => x.EndTime);
- return query.ToList();
- }
- /// <summary>
- /// 获取考试时间信息
- /// </summary>
- /// <param name="timeSegmentID">考试时间ID</param>
- /// <returns></returns>
- public TimeSegmentView GetTimeSegmentView(Guid? timeSegmentID)
- {
- var query = TimeSegmentDAL.GetTimeSegmentView(x => x.TimeSegmentID == timeSegmentID);
- return query.FirstOrDefault();
- }
- /// <summary>
- /// 保存
- /// </summary>
- /// <param name="coursematerial">课程资料实体</param>
- /// <returns></returns>
- public void SaveTimeSegment(TimeSegmentView timeSegmentView)
- {
- EX_TimeSegment timeSegment = new EX_TimeSegment();
- if (timeSegmentView.TimeSegmentID == null || timeSegmentView.TimeSegmentID == Guid.Empty)
- {
- if (timeSegmentView.ExaminationDate < DateTime.Now)
- {
- throw new Exception("考试日期应大于系统当前日期。");
- }
- timeSegment = TimeSegmentDAL.TimeSegmentRepository.GetSingle(x => x.ExaminationDate == timeSegmentView.ExaminationDate
- && x.StartTime == timeSegmentView.StartTime && x.EndTime == timeSegmentView.EndTime);
- if (timeSegment != null)
- {
- if (timeSegment.IsForResit == timeSegmentView.IsForResit)
- {
- throw new Exception("已有相同的考试时间设置,请勿重复设置。");
- }
- else
- {
- throw new Exception("正常考试时间不能和补考考试时间重复,否则协调教室资源会很困难,请调整时间后再保存。");
- }
- }
- timeSegment = new EX_TimeSegment();
- timeSegment.TimeSegmentID = Guid.NewGuid();
- SetNewStatus(timeSegment);
- UnitOfWork.Add(timeSegment);
- }
- else
- {
- timeSegment = TimeSegmentDAL.TimeSegmentRepository.GetSingle(x => x.TimeSegmentID != timeSegmentView.TimeSegmentID
- && x.ExaminationDate == timeSegmentView.ExaminationDate
- && x.StartTime == timeSegmentView.StartTime && x.EndTime == timeSegmentView.EndTime);
- if (timeSegment != null)
- {
- if (timeSegment.IsForResit == timeSegmentView.IsForResit)
- {
- throw new Exception("已有相同的考试时间设置,请勿重复设置。");
- }
- else
- {
- throw new Exception("正常考试时间不能和补考考试时间重复,否则协调教室资源会很困难,请调整时间后再保存。");
- }
- }
- timeSegment = TimeSegmentDAL.TimeSegmentRepository.GetSingle(x => x.TimeSegmentID == timeSegmentView.TimeSegmentID);
- if (timeSegment == null)
- {
- throw new Exception("未能找到需要修改的数据,数据可能已被其他用户更改。");
- }
- SetModifyStatus(timeSegment);
- }
- timeSegment.IsForResit = timeSegmentView.IsForResit;
- timeSegment.ExaminationDate = timeSegmentView.ExaminationDate;
- timeSegment.StartTime = timeSegmentView.StartTime;
- timeSegment.EndTime = timeSegmentView.EndTime;
- UnitOfWork.Commit();
- }
- public void Delete(IList<Guid?> timeSegmentIDList)
- {
- if (timeSegmentIDList.Count > 0)
- {
- UnitOfWork.Delete<EX_TimeSegment>(x => timeSegmentIDList.Contains(x.TimeSegmentID));
- }
- }
- }
- }
|