using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; using EMIS.DataLogic.ScoreManage; using EMIS.ViewModel.ScoreManage; using EMIS.ViewModel; using EMIS.Entities; using Bowin.Common.Linq; using Bowin.Common.Linq.Entity; namespace EMIS.CommonLogic.ScoreManage { public class ScoreParamterCollegeSettingServices : BaseServices, IScoreParamterCollegeSettingServices { public ScoreParameterCollegeSettingDAL ScoreParameterCollegeSettingDAL { get; set; } public IGridResultSet GetScoreParameterCollegeSettingViewGrid(ConfiguretView configuretView, Guid? collegeID, int? yearsID, int? pageIndex, int? pageSize) { Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE); if (collegeID.HasValue) exp = exp.And(x => x.CollegeID == collegeID); if (yearsID.HasValue) exp = exp.And(x => x.Years == yearsID); var query = ScoreParameterCollegeSettingDAL.GetScoreParameterCollegeSettingViewQueryable(exp); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim()); return this.GetQueryByDataRangeByCollege(query) .OrderByDescending(x => x.Years) .ThenBy(x => x.CollegeNo.Length) .ThenBy(x => x.CollegeNo) .ToGridResultSet(pageIndex, pageSize); } public ScoreParameterCollegeSettingView GetScoreParameterCollegeSettingView(Guid scoreParameterCollegeSettingID) { Expression> exp = (x => x.ScoreParameterCollegeSettingID == scoreParameterCollegeSettingID); return this.ScoreParameterCollegeSettingDAL.GetScoreParameterCollegeSettingViewQueryable(exp).FirstOrDefault(); } public List GetScoreParameterSettingViewForDetail(Guid? scoreParameterCollegeSettingID) { Expression> exp = (x => x.ScoreParameterCollegeSettingID == scoreParameterCollegeSettingID); return this.ScoreParameterCollegeSettingDAL.GetScoreParameterSettingViewQueryable(exp).ToList(); } public void Delete(IList scoreParameterCollegeSettingIDList) { this.UnitOfWork.Remove(x => scoreParameterCollegeSettingIDList.Contains(x.ScoreParameterCollegeSettingID)); this.UnitOfWork.Remove(x => scoreParameterCollegeSettingIDList.Contains(x.ScoreParameterCollegeSettingID)); this.UnitOfWork.Commit(); } public void Save(ScoreParameterCollegeSettingView scoreParameterCollegeSettingView, IList detailParameterViewList) { var entity = ScoreParameterCollegeSettingDAL.ScoreParameterCollegeSettingRepository.GetSingle(x => x.ScoreParameterCollegeSettingID == scoreParameterCollegeSettingView.ScoreParameterCollegeSettingID, (x => x.ER_ScoreParameterCollegeSettingDetail)); if (entity == null) { entity = new ER_ScoreParameterCollegeSetting(); entity.ScoreParameterCollegeSettingID = Guid.NewGuid(); this.SetNewStatus(entity); UnitOfWork.Add(entity); } else { this.SetModifyStatus(entity); } var dupEntity = ScoreParameterCollegeSettingDAL.ScoreParameterCollegeSettingRepository.GetSingle(x => x.Years == scoreParameterCollegeSettingView.Years && x.CollegeID == scoreParameterCollegeSettingView.CollegeID && x.ScoreParameterCollegeSettingID != scoreParameterCollegeSettingView.ScoreParameterCollegeSettingID); if (dupEntity != null) { throw(new Exception("该年度已经有其他设置,无法保存。")); } entity.Years = scoreParameterCollegeSettingView.Years; entity.CollegeID = scoreParameterCollegeSettingView.CollegeID; entity.ScoreTypeID = scoreParameterCollegeSettingView.ScoreTypeID; this.UnitOfWork.Remove(x => x.ScoreParameterCollegeSettingID == entity.ScoreParameterCollegeSettingID); entity.ER_ScoreParameterCollegeSettingDetail = new HashSet(); detailParameterViewList.ToList().ForEach(x => { var detail = new ER_ScoreParameterCollegeSettingDetail(); detail.ScoreParameterCollegeSettingDetailID = Guid.NewGuid(); detail.ScoreParameterCollegeSettingID = entity.ScoreParameterCollegeSettingID; detail.ExamsCategoryID = x.ExamsTypeID; detail.CourseTypeID = x.CourseTypeID; detail.ScoreFormulaID = x.ScoreFormulaID; detail.IsTotalFormula = x.IsTotalFormula; detail.CreditFormulaID = x.CreditFormulaID; detail.IsCreditFormula = x.IsCreditFormula; detail.GradePointFormulaID = x.GradePointFormulaID; detail.IsGradePointFormula = x.IsGradePointFormula; UnitOfWork.Add(detail); }); this.UnitOfWork.Commit(); } public ScoreParameterCollegeSettingView GetScoreParameterCollegeSettingView(Guid? collegeID, int? year) { var collegeSetting = ScoreParameterCollegeSettingDAL.GetScoreParameterCollegeSettingViewQueryable(x => x.CollegeID == collegeID && x.Years == year).FirstOrDefault(); if (collegeSetting == null) { collegeSetting = ScoreParameterCollegeSettingDAL.GetScoreParameterCollegeSettingViewQueryable(x => x.CollegeID == null && x.Years == year).FirstOrDefault(); } return collegeSetting; } } }