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; }
///
/// 查询辅修毕业公式信息
///
///
///
///
///
///
public IGridResultSet GetMinorGraduationConditionPackageViewGrid(ConfiguretView configuretView,int? isDefault, int pageIndex, int pageSize)
{
Expression> 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(pageIndex, pageSize);
}
///
/// 查询辅修毕业公式信息List
///
///
///
///
public List GetMinorGraduationConditionPackageViewList(ConfiguretView configuretView, int? isDefault, List idList)
{
//毕业公式
Expression> 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();
}
///
/// 查询单个辅修毕业公式(根据ID)
///
///
///
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);
}
}
///
/// 根据辅修毕业公式ID查询对应的辅修毕业条件信息List
///
///
///
public List 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 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);
}
}
///
/// 删除(当对应的毕业公式被引用时,不可删除--毕业公式、对应的毕业条件)
///
///
///
public bool MinorGraduationConditionPackageDelete(List 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(x => x.MinorGraduationConditionPackageID == minorGraduationConditionPackage.MinorGraduationConditionPackageID);
}
UnitOfWork.Commit();
return true;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
}
}