using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Bowin.Common.Linq.Entity;
using EMIS.ViewModel.MinorManage.MinorSetting;
using EMIS.ViewModel;
using System.Linq.Expressions;
using EMIS.Entities;
using Bowin.Common.Linq;
using EMIS.DataLogic.MinorManage.MinorSetting;
namespace EMIS.CommonLogic.MinorManage.MinorSetting
{
public class MinorControlServices : BaseServices, IMinorControlServices
{
public MinorControlDAL minorControlDAL { get; set; }
///
/// 获取辅修控制列表
///
///
///
///
///
///
///
///
public IGridResultSet GetMinorControlViewList(ConfiguretView configuretView, Guid? schoolyearID, int? GradeyearID, Guid? collegeID, int pageIndex, int pageSize)
{
Expression> exp = x => true;
if (schoolyearID.HasValue)
{
exp = exp.And(x => x.SchoolyearID == schoolyearID);
}
if (GradeyearID.HasValue)
{
exp = exp.And(x => x.GradeyearID == GradeyearID);
}
if (collegeID.HasValue)
{
exp = exp.And(x => x.CollegeID == collegeID);
}
var query = minorControlDAL.GetMinorControlViewQueryable(exp);
if (!string.IsNullOrEmpty(configuretView.ConditionValue) && !string.IsNullOrEmpty(configuretView.Attribute))
{
query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue);
}
query = query.OrderByDescending(x => x.SchoolyearCode).ThenByDescending(x => x.StartDate);
return query.ToGridResultSet(pageIndex, pageSize);
}
///
/// 查询对应的辅修控制信息
///
///
///
public MinorControlView GetMinorControlView(Guid? minorControlID)
{
var query = minorControlDAL.GetMinorControlViewQueryable(x => x.MinorControlID == minorControlID);
return query.FirstOrDefault();
}
///
/// 辅修控制编辑(新增、修改)
///
///
public void MinorControlEdit(MinorControlView minorControlView)
{
try
{
ER_MinorControl minorControl = new ER_MinorControl();
if (minorControlView.MinorControlID == null || minorControlView.MinorControlID == Guid.Empty)
{
//新增、复制新增
minorControl = minorControlDAL.minorControlRepository
.GetSingle(x => x.SchoolyearID == minorControlView.SchoolyearID && x.CollegeID == minorControlView.CollegeID && x.GradeyearID == minorControlView.GradeYearID);
if (minorControl != null)
{
throw new Exception("院系所下已存在相同学年学期的辅修控制信息");
}
minorControl = new ER_MinorControl();
minorControl.MinorControlID = Guid.NewGuid();
minorControl.SchoolyearID = minorControlView.SchoolyearID;
minorControl.GradeyearID = minorControlView.GradeYearID;
minorControl.CollegeID = minorControlView.CollegeID;
minorControl.StartDate = minorControlView.StartDate;
minorControl.EndDate = minorControlView.EndDate;
SetNewStatus(minorControl);
UnitOfWork.Add(minorControl);
}
else
{
//修改
minorControl = minorControlDAL.minorControlRepository
.GetSingle(x => x.MinorControlID != minorControlView.MinorControlID
&& x.SchoolyearID == minorControlView.SchoolyearID && x.CollegeID == minorControlView.CollegeID && x.GradeyearID == minorControlView.GradeYearID);
if (minorControl != null)
{
throw new Exception("院系所下已存在相同学年学期的重修控制信息。");
}
minorControl = minorControlDAL.minorControlRepository
.GetSingle(x => x.MinorControlID == minorControlView.MinorControlID);
if (minorControl == null)
{
throw new Exception("数据有误,请核查。");
}
minorControl.SchoolyearID = minorControlView.SchoolyearID;
minorControl.GradeyearID = minorControlView.GradeYearID;
minorControl.CollegeID = minorControlView.CollegeID;
minorControl.StartDate = minorControlView.StartDate;
minorControl.EndDate = minorControlView.EndDate;
SetModifyStatus(minorControl);
}
UnitOfWork.Commit();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// 辅修控制删除
///
///
public void MinorControlDelete(IList minorControlIDList)
{
try
{
if (minorControlIDList.Count > 0)
{
UnitOfWork.Delete(x => minorControlIDList.Contains(x.MinorControlID));
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
}
}