123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- 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 Bowin.Common.Linq;
- namespace EMIS.CommonLogic.EvaluationManage
- {
- public class EvaluationTableServices : BaseServices, IEvaluationTableServices
- {
- public EvaluationTableDAL evaluationTableDAL { get; set; }
- /// <summary>
- /// 查询评价表信息
- /// </summary>
- /// <param name="configuretView">查询条件实体</param>
- /// <param name="tableType">评价类型</param>
- /// <param name="evaluationType">参评类型</param>
- /// <param name="pageIndex">页码</param>
- /// <param name="pageSize">显示页数</param>
- /// <returns></returns>
- public IGridResultSet<EvaluationTableView> GetEvaluationTableViewGrid(ConfiguretView configuretView, Guid? evaluationType, Guid? evaluationIntType, int? openStatus, int pageIndex, int pageSize)
- {
- var query = evaluationTableDAL.GetEvaluationTableQueryable(x => true);
- if (evaluationIntType.HasValue && evaluationIntType != Guid.Empty)
- {
- query = query.Where(x => x.EvaluationIntTypeID == evaluationIntType);
- }
- if (evaluationType.HasValue && evaluationType != Guid.Empty)
- {
- query = query.Where(x => x.TypeID == evaluationType);
- }
- if (openStatus >= 0)
- {
- query = query.Where(x => x.IsEnabled == openStatus);
- }
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.EvaluationType).OrderBy(x => x.Code).ToGridResultSet<EvaluationTableView>(pageIndex, pageSize);
- return query.OrderBy(x => x.EvaluationType).OrderBy(x => x.Code).ToGridResultSet<EvaluationTableView>(pageIndex, pageSize);
- }
- /// <summary>
- /// 查询评价表信息
- /// </summary>
- /// <param name="configuretView">查询条件实体</param>
- /// <param name="tableType">评价类型</param>
- /// <param name="evaluationType">参评类型</param>
- /// <returns></returns>
- public List<EvaluationTableView> GetEvaluationTableViewList(ConfiguretView configuretView, Guid? evaluationType, Guid? evaluationIntType, int? openStatus)
- {
- var query = evaluationTableDAL.GetEvaluationTableQueryable(x => true);
- if (evaluationIntType.HasValue && evaluationIntType != Guid.Empty)
- {
- query = query.Where(x => x.EvaluationIntTypeID == evaluationIntType);
- }
- if (evaluationType.HasValue && evaluationType != Guid.Empty)
- {
- query = query.Where(x => x.TypeID == evaluationType);
- }
- if (openStatus >= 0)
- {
- query = query.Where(x => x.IsEnabled == openStatus);
- }
- 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();
- }
- /// <summary>
- /// 获取评价表信息
- /// </summary>
- /// <param name="tableID">主键ID</param>
- /// <returns></returns>
- public EM_EvaluationTable GetEvaluationTable(Guid? tableID)
- {
- //查询条件
- Expression<Func<EM_EvaluationTable, bool>> expression = (x => x.EvaluationTableID == tableID.Value);
- return evaluationTableDAL.evaluationTableRepository.GetSingle(expression);
- }
- /// <summary>
- /// 获取评价表信息
- /// </summary>
- /// <param name="Name">评价表名</param>
- /// <returns></returns>
- public EM_EvaluationTable GetEvaluationTable(string Name)
- {
- //查询条件
- Expression<Func<EM_EvaluationTable, bool>> expression = (x => x.Name == Name);
- return evaluationTableDAL.evaluationTableRepository.GetSingle(expression);
- }
- /// <summary>
- /// 获取评价表信息
- /// </summary>
- /// <param name="tableID">主键ID</param>
- /// <returns></returns>
- public EvaluationTableView GetEvaluationTableView(Guid? tableID)
- {
- EvaluationTableView evaluationTableView = new EvaluationTableView();
- if (tableID.HasValue && tableID != Guid.Empty)
- evaluationTableView = evaluationTableDAL.GetEvaluationTableQueryable(x => true).Where(x => x.TableID == tableID).FirstOrDefault();
- return evaluationTableView;
- }
- /// <summary>
- /// 添加
- /// </summary>
- /// <param name="evaluationTable">实体</param>
- /// <returns></returns>
- public bool EvaluationTableAdd(EM_EvaluationTable evaluationTable)
- {
- try
- {
- UnitOfWork.Add(evaluationTable);
- UnitOfWork.Commit();
- return true;
- }
- catch (Exception)
- {
- throw;
- }
- }
- /// <summary>
- /// 修改
- /// </summary>
- /// <param name="evaluationTable">实体</param>
- /// <returns></returns>
- public bool EvaluationTableUpdate(EM_EvaluationTable evaluationTable)
- {
- try
- {
- UnitOfWork.Update(evaluationTable);
- UnitOfWork.Commit();
- return true;
- }
- catch (Exception)
- {
- throw;
- }
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="tableIDs"></param>
- /// <returns></returns>
- public bool EvaluationTableDelete(List<Guid> tableIDs)
- {
- try
- {
- UnitOfWork.Delete<EM_EvaluationTable>(x => tableIDs.Contains(x.EvaluationTableID));
- UnitOfWork.Commit();
- return true;
- }
- catch (Exception)
- {
- throw;
- }
- }
- public bool ValidateEvaluationTable(Guid? tableID, string name, string code)
- {
- if (string.IsNullOrWhiteSpace(code))
- {
- throw new Exception("评价表编号不能为空!");
- }
- if (string.IsNullOrWhiteSpace(name))
- {
- throw new Exception("评价表名不能为空!");
- }
- code = code.Trim();
- name = name.Trim();
- Expression<Func<EM_EvaluationTable, bool>> codeFilter = w => w.Code == code;
- Expression<Func<EM_EvaluationTable, bool>> nameFilter = w => w.Name == name;
- if (tableID.HasValue && tableID != Guid.Empty) //编辑状态
- {
- codeFilter = codeFilter.And(w => w.EvaluationTableID != tableID);
- nameFilter = nameFilter.And(w => w.EvaluationTableID != tableID);
- }
- var hasCode = evaluationTableDAL.evaluationTableRepository.Entities.Any(codeFilter);
- if (hasCode)
- {
- throw new Exception("评价表编号已存在!");
- }
- var hasName = evaluationTableDAL.evaluationTableRepository.Entities.Any(nameFilter);
- if (hasName)
- {
- throw new Exception("评价表名已存在!");
- }
- return true;
- }
- public void SaveOrUpdateEvaluationTable(EvaluationTableView model)
- {
- ValidateEvaluationTable(model.TableID, model.Name, model.Code);
- var user = EMIS.Utility.FormValidate.CustomPrincipal.Current;
- EM_EvaluationTable entity;
- var entityList = evaluationTableDAL.evaluationTableRepository.Entities.Where(x => x.EvaluationIntTypeID == model.EvaluationIntTypeID && x.EvaluationTypeID == model.TypeID).ToList();
- if (model.TableID.HasValue && model.TableID != Guid.Empty)
- {
- //entity = entityList.FirstOrDefault(x => x.TableID == model.TableID);
- entity = GetEvaluationTable(model.TableID);
- entityList.Remove(entity);//移除
- entity.Code = model.Code;
- entity.Name = model.Name;
- entity.EvaluationIntTypeID = model.EvaluationIntTypeID;
- entity.EvaluationTypeID = model.TypeID;
- entity.Weight = model.Weight;
- entity.Remark = model.Remark;
- entity.ModifyUserID = user.UserID;
- entity.ModifyTime = DateTime.Now;
- entity.IsEnabled = model.IsEnabled == (int)CF_YesOrNoStatus.Yes ? true : false;
- UnitOfWork.Update(entity);
- }
- else
- {
- entity = new EM_EvaluationTable();
- entity.EvaluationTableID = Guid.NewGuid();
- entity.Code = model.Code;
- entity.Name = model.Name;
- entity.EvaluationIntTypeID = model.EvaluationIntTypeID;
- entity.EvaluationTypeID = model.TypeID;
- entity.Weight = model.Weight;
- entity.Remark = model.Remark;
- entity.ModifyUserID = user.UserID;
- entity.ModifyTime = DateTime.Now;
- entity.CreateTime = DateTime.Now;
- entity.CreateUserID = user.UserID;
- entity.IsEnabled = model.IsEnabled == (int)CF_YesOrNoStatus.Yes ? true : false;
- UnitOfWork.Add(entity);
- }
- if (entity.IsEnabled == true)
- {
- entityList.ForEach(item => item.IsEnabled = false);
- }
- UnitOfWork.Commit();
- }
- }
- }
|