123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Bowin.Common.Linq.Entity;
- using EMIS.ViewModel.MinorGraduation.MinorGraduationSetting;
- using EMIS.ViewModel;
- using Bowin.Common.Linq;
- using System.Linq.Expressions;
- using EMIS.Entities;
- using EMIS.DataLogic.MinorGraduation.MinorGraduationSetting;
- namespace EMIS.CommonLogic.MinorGraduation.MinorGraduationSetting
- {
- public class MinorGraduationConditionPackageServices : BaseServices, IMinorGraduationConditionPackageServices
- {
- public MinorGraduationConditionPackageDAL minorGraduationConditionPackageDAL { get; set; }
- /// <summary>
- /// 查询辅修毕业公式信息
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="isDefault"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <returns></returns>
- public IGridResultSet<MinorGraduationConditionPackageView> GetMinorGraduationConditionPackageViewGrid(ConfiguretView configuretView,int? isDefault, int pageIndex, int pageSize)
- {
- Expression<Func<ER_MinorGraduationConditionPackage, bool>> exp = (x => true);
- if (isDefault.HasValue)
- {
- if (isDefault == 1)
- {
- exp = exp.And(x => x.IsDefault.Value == true);
- }
- if (isDefault == 0)
- {
- exp = exp.And(x => x.IsDefault.Value != true);
- }
- }
- var query = minorGraduationConditionPackageDAL.GetMinorGraduationConditionPackageQueryable(exp);
- //查询条件
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- {
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
- }
- return query.OrderByDescending(x => x.IsDefault).ThenBy(x => x.Title.Length).ThenBy(x => x.Title)
- .ToGridResultSet<MinorGraduationConditionPackageView>(pageIndex, pageSize);
- }
- /// <summary>
- /// 查询辅修毕业公式信息List
- /// </summary>
- /// <param name="configuretView"></param>
- /// <param name="isDefault"></param>
- /// <returns></returns>
- public List<MinorGraduationConditionPackageView> GetMinorGraduationConditionPackageViewList(ConfiguretView configuretView, int? isDefault, List<Guid?> idList)
- {
- //毕业公式
- Expression<Func<ER_MinorGraduationConditionPackage, bool>> exp = (x => true);
- if (isDefault.HasValue)
- {
- if (isDefault == 1)
- {
- exp = exp.And(x => x.IsDefault.Value == true);
- }
- if (isDefault == 0)
- {
- exp = exp.And(x => x.IsDefault.Value != true);
- }
- }
- if (idList != null && idList.Count > 0)
- {
- exp = exp.And(x => idList.Contains(x.MinorGraduationConditionPackageID));
- }
- var query = minorGraduationConditionPackageDAL.GetMinorGraduationConditionPackageQueryable(exp);
- //查询条件
- if (!string.IsNullOrEmpty(configuretView.ConditionValue))
- {
- query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
- }
- return query.OrderByDescending(x => x.IsDefault)
- .ThenBy(x => x.Title.Length).ThenBy(x => x.Title).ToList();
- }
- public MinorGraduationConditionPackageView GetDefaultMinorGraduationConditionPackageView()
- {
- var query = minorGraduationConditionPackageDAL.GetMinorGraduationConditionPackageQueryable(x => x.IsDefault == true);
- return query.FirstOrDefault();
- }
- /// <summary>
- /// 查询单个辅修毕业公式(根据ID)
- /// </summary>
- /// <param name="GraduationConditionPackageID"></param>
- /// <returns></returns>
- public MinorGraduationConditionPackageView GetMinorGraduationConditionPackageView(Guid? minorGraduationConditionPackageID)
- {
- try
- {
- var query = minorGraduationConditionPackageDAL
- .GetMinorGraduationConditionPackageQueryable(x => x.MinorGraduationConditionPackageID == minorGraduationConditionPackageID)
- .SingleOrDefault();
- return query;
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- /// <summary>
- /// 根据辅修毕业公式ID查询对应的辅修毕业条件信息List
- /// </summary>
- /// <param name="GraduationConditionPackageID"></param>
- /// <returns></returns>
- public List<MinorGraduationConditionView> GetMinorGraduationConditionViewList(Guid? minorGraduationConditionPackageID)
- {
- var query = minorGraduationConditionPackageDAL
- .MinorGraduationConditionQueryable(x => x.MinorGraduationConditionPackageID == minorGraduationConditionPackageID);
- return query.OrderBy(x => x.Title.Length).ThenBy(x => x.Title).ToList();
- }
- public void MinorGraduationConditionPackageEdit(MinorGraduationConditionPackageView minorGraduationConditionPackageView,
- IList<MinorGraduationConditionView> minorGraduationConditionViewList)
- {
- try
- {
- //查询数据库进行验证
- var minorGraduationConditionPackageVerification = minorGraduationConditionPackageDAL.minorGraduationConditionPackageRepository
- .GetList(x => x.MinorGraduationConditionPackageID != minorGraduationConditionPackageView.MinorGraduationConditionPackageID
- && x.Title == minorGraduationConditionPackageView.Title)
- .SingleOrDefault();
- //列表页面对应的毕业条件IDList
- var minorGraduationConditionIDList = minorGraduationConditionViewList.Select(x => x.MinorGraduationConditionID).ToList();
- //列表页面对应的毕业条件信息List
- var minorGraduationConditionList = minorGraduationConditionPackageDAL.minorGraduationConditionRepository
- .GetList(x => minorGraduationConditionIDList.Contains(x.MinorGraduationConditionID)).ToList();
- if (minorGraduationConditionPackageVerification == null)
- {
- //数据有误验证
- if (minorGraduationConditionPackageView.MinorGraduationConditionPackageID != Guid.Empty)
- {
- var minorGraduationConditionPackage = minorGraduationConditionPackageDAL.minorGraduationConditionPackageRepository
- .GetList(x => x.MinorGraduationConditionPackageID == minorGraduationConditionPackageView.MinorGraduationConditionPackageID)
- .SingleOrDefault();
- if (minorGraduationConditionPackage == null)
- {
- throw new Exception("数据有误,请核查");
- }
- else
- {
- //表示修改
- ////注:当毕业申请、毕业审核、毕业名单中有引用相关的毕业公式时,不可对相应的毕业公式进行修改--是否默认列除外
- ////根据毕业公式查询对应的毕业申请、毕业审核、毕业名单信息(外键引用)
- //var graduationApplyList = GraduationConditionPackageDAL.GraduationApplyRepository
- // .GetList(x => x.GraduationConditionPackageID == graduationConditionPackageView.GraduationConditionPackageID).ToList();
- //判断是否默认状态(同一种学生类别,只能启用一种默认公式)
- if (minorGraduationConditionPackageView.IsDefault)
- {
- var minorGraduationConditionPackageList = minorGraduationConditionPackageDAL
- .minorGraduationConditionPackageRepository
- .GetList(x => x.StudentType == minorGraduationConditionPackageView.StudentTypeID && x.IsDefault.Value
- && x.MinorGraduationConditionPackageID != minorGraduationConditionPackageView.MinorGraduationConditionPackageID)
- .ToList();
- minorGraduationConditionPackageList.ForEach(x => x.IsDefault = false);
- }
- minorGraduationConditionPackage.Title = minorGraduationConditionPackageView.Title;
- minorGraduationConditionPackage.StudentType = minorGraduationConditionPackageView.StudentTypeID;
- minorGraduationConditionPackage.IsDefault = minorGraduationConditionPackageView.IsDefault;
- SetModifyStatus(minorGraduationConditionPackage);
- ////查询毕业公式对应的毕业条件信息
- //var gradPackageConditionList = GraduationConditionPackageDAL
- // .GraduationConditionQueryable(x => x.GraduationConditionPackageID == graduationConditionPackageView.GraduationConditionPackageID)
- // .ToList();
- ////查询毕业公式对应的毕业条件IDList
- //var gradPackageConditionIDList = gradPackageConditionList.Select(x => x.GraduationConditionID).ToList();
- ////先删除毕业公式对应的全部毕业条件信息,再对选择的毕业条件进行新增
- //graduationConditionPackage.ER_GraduationCondition
- // .RemoveWhere(x => gradPackageConditionIDList.Contains(x.GraduationConditionID));
- //删除
- UnitOfWork.Delete(minorGraduationConditionPackage, (x => x.ER_MinorGraduationCondition));
- //对应的毕业条件
- if (minorGraduationConditionViewList != null && minorGraduationConditionViewList.Count() > 0)
- {
- foreach (var minorGraduationCondition in minorGraduationConditionList)
- {
- minorGraduationConditionPackage.ER_MinorGraduationCondition.Add(minorGraduationCondition);
- }
- }
- }
- }
- else
- {
- //表示新增
- //判断是否默认状态(同一种学生类别,只能启用一种默认公式)
- if (minorGraduationConditionPackageView.IsDefault)
- {
- var graduationConditionPackageList = minorGraduationConditionPackageDAL
- .minorGraduationConditionPackageRepository
- .GetList(x => x.StudentType == minorGraduationConditionPackageView.StudentTypeID && x.IsDefault.Value)
- .ToList();
- graduationConditionPackageList.ForEach(x => x.IsDefault = false);
- }
- ER_MinorGraduationConditionPackage minorGraduationConditionPackage = new ER_MinorGraduationConditionPackage();
- minorGraduationConditionPackage.MinorGraduationConditionPackageID = Guid.NewGuid();
- minorGraduationConditionPackage.Title = minorGraduationConditionPackageView.Title;
- minorGraduationConditionPackage.StudentType = minorGraduationConditionPackageView.StudentTypeID;
- minorGraduationConditionPackage.IsDefault = minorGraduationConditionPackageView.IsDefault;
- SetNewStatus(minorGraduationConditionPackage);
-
- //对应的毕业条件
- if (minorGraduationConditionViewList != null && minorGraduationConditionViewList.Count() > 0)
- {
- foreach (var minorGraduationCondition in minorGraduationConditionList)
- {
- minorGraduationConditionPackage.ER_MinorGraduationCondition.Add(minorGraduationCondition);
- }
- }
- UnitOfWork.Add(minorGraduationConditionPackage);
- }
- //事务提交
- UnitOfWork.Commit();
- }
- else
- {
- throw new Exception("已存在相同的辅修毕业公式,请核查");
- }
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- /// <summary>
- /// 删除(当对应的毕业公式被引用时,不可删除--毕业公式、对应的毕业条件)
- /// </summary>
- /// <param name="graduationConditionPackageIDs"></param>
- /// <returns></returns>
- public bool MinorGraduationConditionPackageDelete(List<Guid?> minorGraduationConditionPackageIDs)
- {
- try
- {
- //查找公式是否被引用
- var minorGraduationApplyList = minorGraduationConditionPackageDAL.minorGraduationApplyRepository
- .GetList(x => minorGraduationConditionPackageIDs.Contains(x.MinorGraduationConditionPackageID)).ToList();
- if (minorGraduationApplyList != null && minorGraduationApplyList.Count() > 0)
- {
- throw new Exception("选择的公式已经被引用,不能删除");
- }
- //查询相应的毕业公式及对应的毕业条件信息List
- var minorGraduationConditionPackageList = minorGraduationConditionPackageDAL.minorGraduationConditionPackageRepository
- .GetList(x => minorGraduationConditionPackageIDs.Contains(x.MinorGraduationConditionPackageID), x => x.ER_MinorGraduationCondition)
- .ToList();
- foreach (var minorGraduationConditionPackage in minorGraduationConditionPackageList)
- {
- //删除
- UnitOfWork.Delete(minorGraduationConditionPackage, (x => x.ER_MinorGraduationCondition));
- UnitOfWork.Delete<ER_MinorGraduationConditionPackage>(x => x.MinorGraduationConditionPackageID == minorGraduationConditionPackage.MinorGraduationConditionPackageID);
- }
- UnitOfWork.Commit();
- return true;
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- }
- }
|