using EMIS.ViewModel.EvaluationManage; using System; using System.Collections.Generic; using System.Linq; using System.Text; using Bowin.Common.Linq; using Bowin.Common.Linq.Entity; using EMIS.DataLogic.Common.EvaluationManage; using EMIS.Entities; using System.Linq.Expressions; namespace EMIS.CommonLogic.EvaluationManage { public class EvaluationIntTypeServices : BaseServices, IEvaluationIntTypeServices { public EvaluationIntTypeDAL evaluationIntTypeDAL { get; set; } /// /// 列表信息 /// /// /// /// /// /// public IGridResultSet GetEvaluationIntTypeViewGrid(ViewModel.ConfiguretView configuretView, int? intType, int pageIndex, int pageSize) { Expression> exp = x => true; if (intType.HasValue && intType > 0) { exp = exp.And(x => x.EM_EvaluationTeachingMode.Select(w => w.TeachingModeID).Contains(intType)); } var query = evaluationIntTypeDAL.GetEvaluationIntTypeQueryable(exp); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); } var result = query.OrderBy(x => x.Code.Length).ThenBy(x => x.Code).ToGridResultSet(pageIndex, pageSize); var evaluationIntTypeIDList = result.rows.Select(x => x.EvaluationIntTypeID).ToList(); var querEvaluationTeachingModeTypeView = evaluationIntTypeDAL.GetEvaluationTeachingModeTypeQuery(x => evaluationIntTypeIDList.Contains(x.EvaluationIntTypeID)).ToList(); result.rows.ForEach(x => x.TeachingModeTypeViewList = new HashSet(querEvaluationTeachingModeTypeView.Where(y => y.EvaluationIntTypeID == x.EvaluationIntTypeID))); return result; } public List GetEvaluationIntTypeViewList(ViewModel.ConfiguretView configuretView, int? intType) { Expression> exp = x => true; if (intType.HasValue && intType > 0) { exp = exp.And(x => x.EM_EvaluationTeachingMode.Select(w => w.TeachingModeID).Contains(intType)); } var query = evaluationIntTypeDAL.GetEvaluationIntTypeQueryable(exp); if (!string.IsNullOrEmpty(configuretView.ConditionValue)) { query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue); } var result = query.OrderBy(x => x.Code.Length).ThenBy(x => x.Code).ToList(); var evaluationIntTypeIDList = result.Select(x => x.EvaluationIntTypeID).ToList(); var querEvaluationTeachingModeTypeView = evaluationIntTypeDAL.GetEvaluationTeachingModeTypeQuery(x => evaluationIntTypeIDList.Contains(x.EvaluationIntTypeID)).ToList(); result.ForEach(x => x.TeachingModeTypeViewList = new HashSet(querEvaluationTeachingModeTypeView.Where(y => y.EvaluationIntTypeID == x.EvaluationIntTypeID))); return result.ToList(); } /// /// 编辑新增 /// /// public void SaveOrUpdateEvaluationIntType(EvaluationIntTypeView model) { if (model.EvaluationIntTypeID == Guid.Empty || model.EvaluationIntTypeID == null) { EM_EvaluationIntType evaluationIntType = new EM_EvaluationIntType(); evaluationIntType.EvaluationIntTypeID = Guid.NewGuid(); evaluationIntType.Code = model.Code; evaluationIntType.Name = model.Name; evaluationIntType.Remark = model.Remark; SetNewStatus(evaluationIntType); UnitOfWork.Add(evaluationIntType); if (model.TeachingModeTypeID == null || model.TeachingModeTypeID.Count() < 0) { throw new Exception("授课方式不能为空。"); } model.TeachingModeTypeID.ForEach(x => { EM_EvaluationTeachingMode evaluationTeachingMode = new EM_EvaluationTeachingMode(); evaluationTeachingMode.EvaluationTeachingModeID = Guid.NewGuid(); evaluationTeachingMode.EvaluationIntTypeID = evaluationIntType.EvaluationIntTypeID; evaluationTeachingMode.TeachingModeID = x;//授课方式 SetNewStatus(evaluationTeachingMode); UnitOfWork.Add(evaluationTeachingMode); }); } else { if (model.TeachingModeTypeID == null || model.TeachingModeTypeID.Count() < 0) { throw new Exception("授课方式不能为空。"); } EM_EvaluationIntType evaluationIntType = evaluationIntTypeDAL.evaluationIntTypeRepository. GetSingle(x => x.EvaluationIntTypeID == model.EvaluationIntTypeID); evaluationIntType.Code = model.Code; evaluationIntType.Name = model.Name; evaluationIntType.Remark = model.Remark; Guid EvaluationIntTypeIDList = evaluationIntType.EvaluationIntTypeID; UnitOfWork.Delete(x => x.EvaluationIntTypeID == EvaluationIntTypeIDList);//先删除评价类型授课方式再重新添加 SetModifyStatus(evaluationIntType); UnitOfWork.Update(evaluationIntType); model.TeachingModeTypeID.ForEach(x => { EM_EvaluationTeachingMode evaluationTeachingMode = new EM_EvaluationTeachingMode(); evaluationTeachingMode.EvaluationTeachingModeID = Guid.NewGuid(); evaluationTeachingMode.EvaluationIntTypeID = evaluationIntType.EvaluationIntTypeID; evaluationTeachingMode.TeachingModeID = x;//授课方式 SetNewStatus(evaluationTeachingMode); UnitOfWork.Add(evaluationTeachingMode); }); } UnitOfWork.Commit(); } /// /// 删除操作 /// /// /// public bool EvaluationIntTypeDelete(List IntTypeIDs) { try { //设置极联删除~~ UnitOfWork.Delete(x => IntTypeIDs.Contains((Guid)x.EvaluationIntTypeID));//删除评价类型授课方式 UnitOfWork.Delete(x => IntTypeIDs.Contains(x.EvaluationIntTypeID));//删除评价类型 return true; } catch (Exception) { throw; } } /// /// 加载授课方式 /// /// /// public List GetTeachingMode(Guid? evaluationIntTypeID) { return evaluationIntTypeDAL.GetTeachingModeTypeQueryble(evaluationIntTypeID); } public EvaluationIntTypeView GetEvaluationIntTypeView(Guid? evaluationIntTypeID) { EvaluationIntTypeView evaluationIntTypeView = new EvaluationIntTypeView(); if (evaluationIntTypeID.HasValue && evaluationIntTypeID != Guid.Empty) { evaluationIntTypeView = evaluationIntTypeDAL.GetEvaluationIntTypeQueryable(x => true).Where(x => x.EvaluationIntTypeID == evaluationIntTypeID).FirstOrDefault(); } return evaluationIntTypeView; } } }