using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EMIS.DataLogic.Repositories;
using EMIS.ViewModel;
using Bowin.Common.Linq.Entity;
using EMIS.Entities;
using EMIS.ViewModel.ScoreManage;
namespace EMIS.CommonLogic.ScoreManage
{
public class CreditFormulaServices : BaseServices, ICreditFormulaServices
{
public CreditFormulaRepository creditFormulaRepository { get; set; }
///
/// 成绩学分公式设置
///
///
///
///
///
public Bowin.Common.Linq.Entity.IGridResultSet GetCreditFormulaGrid(string name, int pageIndex, int pageSize)
{
var query = creditFormulaRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
if (!string.IsNullOrEmpty(name))
query = query.Where(x => x.Name.Contains(name));
return query.OrderByDescending(x => x.CreateTime).ToGridResultSet(pageIndex, pageSize);
}
///
/// 成绩学分公式设置
///
///
///
public List GetCreditFormulaList(string name)
{
var query = creditFormulaRepository.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
if (!string.IsNullOrEmpty(name))
query = query.Where(x => x.Name.Contains(name));
return query.OrderByDescending(x => x.CreateTime).ToList();
}
///
/// 查询成绩学分公式设置对象
///
///
///
public Entities.ER_CreditFormula GetCreditFormula(Guid? creditFormulaID)
{
return creditFormulaRepository.GetSingle(x => x.CreditFormulaID == creditFormulaID);
}
///
/// 添加
///
///
public void CreditFormulaAdd(CreditFormulaView creditFormulaView)
{
try
{
ER_CreditFormula creditFormula = null;
if (creditFormulaView.CreditFormulaID == null || creditFormulaView.CreditFormulaID == Guid.Empty)
{
creditFormula = new ER_CreditFormula();
creditFormula.CreditFormulaID = Guid.NewGuid();
creditFormula.Name = creditFormulaView.Name;
creditFormula.Scores = creditFormulaView.Scores;
SetNewStatus(creditFormula);
UnitOfWork.Add(creditFormula);
}
else
{
creditFormula = GetCreditFormula(creditFormulaView.CreditFormulaID);
if(creditFormula == null)
throw new Exception("未找到相对应的成绩学分公式设置!");
creditFormula.Name = creditFormulaView.Name;
creditFormula.Scores = creditFormulaView.Scores;
SetModifyStatus(creditFormula);
}
UnitOfWork.Commit();
}
catch (Exception)
{
throw;
}
}
///
/// 根据成绩公式设置ID查询明细
///
///
///
public void CreditFormulaDelete(List creditFormulaIDs)
{
try
{
if (creditFormulaIDs.Count > 0)
{
UnitOfWork.Delete(x => creditFormulaIDs.Contains(x.CreditFormulaID));
}
}
catch (Exception)
{
throw;
}
}
}
}