using System; using System.Collections.Generic; using System.Linq; using System.Text; using EMIS.DataLogic.Common.EvaluationManage; using Bowin.Common.Linq.Entity; using EMIS.Entities; using EMIS.ViewModel; using System.Linq.Expressions; using EMIS.ViewModel.EvaluationManage; using EMIS.CommonLogic.SystemServices; namespace EMIS.CommonLogic.EvaluationManage { public class EvaluationTypeServices : BaseServices, IEvaluationTypeServices { public EvaluationTypeDAL evaluationTypeDAL { get; set; } public ISerialNumberServices SerialNumberServices { get; set; } /// /// 查询参评类型信息 /// /// 查询条件实体 /// 页码 /// 显示页数 /// public IGridResultSet GetEvaluationTypeViewGrid(ConfiguretView configuretView, int? isStudent, int? isDefault, int pageIndex, int pageSize) { var query = evaluationTypeDAL.GetEvaluationTypeQueryable(x => true); if (isStudent.HasValue && isStudent > -1) { bool student = isStudent == 1 ? true : false; query = query.Where(x => x.IsStudent == student); } if (isDefault.HasValue && isDefault > -1) { bool isdefault = isDefault == 1 ? true : false; query = query.Where(x => x.IsDefault == isdefault); } if (!string.IsNullOrEmpty(configuretView.ConditionValue)) return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderByDescending(x => x.Name).ToGridResultSet(pageIndex, pageSize); return query.OrderByDescending(x => x.Name).ToGridResultSet(pageIndex, pageSize); } /// /// 查询参评类型信息 /// /// 查询条件实体 /// public List GetEvaluationTypeViewList(ConfiguretView configuretView, int? isStudent, int? isDefault) { var query = evaluationTypeDAL.GetEvaluationTypeQueryable(x => true); if (isStudent.HasValue && isStudent > -1) { bool student = isStudent == 1 ? true : false; query = query.Where(x => x.IsStudent == student); } if (isDefault.HasValue && isDefault > -1) { bool isdefault = isDefault == 1 ? true : false; query = query.Where(x => x.IsDefault == isdefault); } if (!string.IsNullOrEmpty(configuretView.ConditionValue)) return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderByDescending(x => x.CreateTime).ToList(); return query.OrderByDescending(x => x.CreateTime).ToList(); } /// /// 获取参评类型信息 /// /// 主键ID /// public EMIS.Entities.EM_EvaluationType GetEvaluationType(Guid? typeID) { //查询条件 Expression> expression = (x => x.EvaluationTypeID == typeID.Value); return evaluationTypeDAL.evaluationTypeRepository.GetSingle(expression); } /// /// 获取参评类型信息 /// /// 参评类型 /// public EMIS.Entities.EM_EvaluationType GetEvaluationType(string Name) { //查询条件 Expression> expression = (x => x.Name == Name); return evaluationTypeDAL.evaluationTypeRepository.GetSingle(expression); } /// /// 获取参评类型信息 /// /// 主键ID /// public EvaluationTypeView GetEvaluationTypeView(Guid? typeID) { EvaluationTypeView evaluationTypeView = new EvaluationTypeView(); if (typeID.HasValue) evaluationTypeView = evaluationTypeDAL.GetEvaluationTypeQueryable(x => true).Where(x => x.TypeID == typeID).FirstOrDefault(); return evaluationTypeView; } /// /// 添加 /// /// 实体 /// public bool EvaluationTypeAdd(EMIS.Entities.EM_EvaluationType evaluationType) { try { UnitOfWork.Add(evaluationType); UnitOfWork.Commit(); return true; } catch (Exception) { throw; } } /// /// 修改 /// /// 实体 /// public bool EvaluationTypeUpdate(EMIS.Entities.EM_EvaluationType evaluationType) { try { UnitOfWork.Update(evaluationType); UnitOfWork.Commit(); return true; } catch (Exception) { throw; } } /// /// 保存或新增参评类型 /// /// public void SaveOrUpdateEvaluationType(EvaluationTypeView model) { var user = EMIS.Utility.FormValidate.CustomPrincipal.Current; EM_EvaluationType entity; var entities = evaluationTypeDAL.evaluationTypeRepository.Entities.ToList(); if (!model.TypeID.HasValue || model.TypeID == Guid.Empty) { entity = new EM_EvaluationType(); entity.EvaluationTypeID = Guid.NewGuid(); entity.CreateTime = DateTime.Now; entity.CreateUserID = user.UserID; //entity.Code = model.Code; UnitOfWork.Add(entity); } else { entity = entities.FirstOrDefault(w => w.EvaluationTypeID == model.TypeID); entities.Remove(entity); //UnitOfWork.Update(entity); } //entity.Name = model.Name; //entity.IsStudent = model.IsStudent; //entity.IsDefault = model.IsDefault; entity.StartTime = model.StartTime; entity.EndTime = model.EndTime; entity.Number = model.Number; entity.Remark = model.Remark; entity.ModifyUserID = user.UserID; entity.ModifyTime = DateTime.Now; if (entity.IsStudent == true) { //UnitOfWork.Update(a => new EM_EvaluationType { IsDefault = false }, w => true); entities.ForEach(item => item.IsStudent = false); } UnitOfWork.Commit(); } /// /// 删除 /// /// /// public bool EvaluationTypeDelete(List typeIDs) { try { UnitOfWork.Delete(x => typeIDs.Contains(x.EvaluationTypeID)); UnitOfWork.Commit(); return true; } catch (Exception) { throw; } } } }