using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EMIS.DataLogic.Repositories;
using EMIS.Entities;
using Bowin.Common.Linq.Entity;
using EMIS.ViewModel;
using EMIS.DataLogic.Common.AdministrativeOrgan;
using System.Linq.Expressions;
namespace EMIS.CommonLogic.AdministrativeOrgan
{
public class UniversityServices : BaseServices,IUniversityServices
{
public UniversityDAL UniversityDAL { get; set; }
///
/// 查询学校信息View
///
///
///
///
///
public IGridResultSet GetUniversityViewGrid(ConfiguretView configuretView, int pageIndex, int pageSize)
{
//学校信息
Expression> expUniversity = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
var query = UniversityDAL.GetUniversityViewQueryable(expUniversity);
//查询条件
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
{
query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
}
return query
.OrderBy(x => x.Code.Length).ThenBy(x => x.Code)
.ToGridResultSet(pageIndex, pageSize);
}
///
/// 查询学校信息List
///
///
///
public IList GetUniversityViewList(ConfiguretView configuretView)
{
//学校信息
Expression> expUniversity = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
var query = UniversityDAL.GetUniversityViewQueryable(expUniversity);
//查询条件
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
{
query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
}
return query
.OrderBy(x => x.Code.Length).ThenBy(x => x.Code)
.ToList();
}
///
/// 查询全部学校信息CF_University
///
///
public List GetUniversityList()
{
//学校信息
Expression> expUniversity = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
var query = UniversityDAL.UniversityRepository.GetList(expUniversity);
return query
.OrderBy(x => x.Code.Length).ThenBy(x => x.Code)
.ToList();
}
///
/// 查询对应的学校信息UniversityView
///
///
///
public UniversityView GetUniversityView(Guid? universityID)
{
try
{
var query = UniversityDAL.GetUniversityViewQueryable(x => x.UniversityID == universityID)
.SingleOrDefault();
return query;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// 编辑(新增、修改,业务主键:学校代码或学校名称)
///
///
public void UniversityEdit(UniversityView universityView)
{
try
{
//查询数据库进行验证
var universityVerification = UniversityDAL.UniversityRepository
.GetList(x => x.UniversityID != universityView.UniversityID
&& (x.Code == universityView.Code
|| x.Name == universityView.Name))
.FirstOrDefault();
if (universityVerification == null)
{
//数据有误验证
if (universityView.UniversityID != Guid.Empty)
{
var university = UniversityDAL.UniversityRepository
.GetList(x => x.UniversityID == universityView.UniversityID)
.SingleOrDefault();
var universityProfile = UniversityDAL.UniversityProfileRepository
.GetList(x => x.UniversityID == universityView.UniversityID)
.SingleOrDefault();
if (university == null)
{
throw new Exception("数据有误,请核查");
}
else
{
//表示修改
university.Code = universityView.Code;
university.Name = universityView.Name;
university.SimpleName = universityView.SimpleName;
university.EnglishName = universityView.EnglishName;
university.Remark = universityView.Remark;
SetModifyStatus(university);
//学校信息扩展表
if (universityProfile == null)
{
//新增
var newUniversityProfile = new CF_UniversityProfile();
newUniversityProfile.UniversityID = universityView.UniversityID;
newUniversityProfile.ProvinceID = universityView.ProvinceID;
newUniversityProfile.CityID = universityView.CityID;
newUniversityProfile.DistrictID = universityView.DistrictID;
newUniversityProfile.PropertyID = universityView.PropertyID;
newUniversityProfile.SchoolTypeID = universityView.SchoolTypeID;
newUniversityProfile.ManagerID = universityView.ManagerID;
newUniversityProfile.FounderTypeID = universityView.FounderTypeID;
newUniversityProfile.SchoolLevelID = universityView.SchoolLevelID;
newUniversityProfile.HeadMasterName = universityView.HeadMasterName;
newUniversityProfile.PartyManageID = universityView.PartyManageID;
newUniversityProfile.LegalPersonName = universityView.LegalPersonName;
newUniversityProfile.BuildDate = universityView.BuildDate;
newUniversityProfile.AnniversaryDate = universityView.AnniversaryDate;
newUniversityProfile.SchoolBasis = universityView.SchoolBasis;
newUniversityProfile.SchoolMotto = universityView.SchoolMotto;
newUniversityProfile.SubjectCount = universityView.SubjectCount;
newUniversityProfile.Is211University = universityView.Is211University;
newUniversityProfile.IsKeyUniversity = universityView.IsKeyUniversity;
newUniversityProfile.IsAdultCollege = universityView.IsAdultCollege;
newUniversityProfile.IsPostCollege = universityView.IsPostCollege;
newUniversityProfile.IsNetCollege = universityView.IsNetCollege;
newUniversityProfile.Telephone = universityView.Telephone;
newUniversityProfile.ZIPCode = universityView.ZIPCode;
newUniversityProfile.Email = universityView.Email;
newUniversityProfile.FAX = universityView.FAX;
newUniversityProfile.PublicNum = universityView.PublicNum;
newUniversityProfile.HomePage = universityView.HomePage;
newUniversityProfile.Address = universityView.Address;
newUniversityProfile.EnglishAddress = universityView.EnglishAddress;
newUniversityProfile.HistoryEvolution = universityView.HistoryEvolution;
SetNewStatus(newUniversityProfile);
UnitOfWork.Add(newUniversityProfile);
}
else
{
//修改
universityProfile.ProvinceID = universityView.ProvinceID;
universityProfile.CityID = universityView.CityID;
universityProfile.DistrictID = universityView.DistrictID;
universityProfile.PropertyID = universityView.PropertyID;
universityProfile.SchoolTypeID = universityView.SchoolTypeID;
universityProfile.ManagerID = universityView.ManagerID;
universityProfile.FounderTypeID = universityView.FounderTypeID;
universityProfile.SchoolLevelID = universityView.SchoolLevelID;
universityProfile.HeadMasterName = universityView.HeadMasterName;
universityProfile.PartyManageID = universityView.PartyManageID;
universityProfile.LegalPersonName = universityView.LegalPersonName;
universityProfile.BuildDate = universityView.BuildDate;
universityProfile.AnniversaryDate = universityView.AnniversaryDate;
universityProfile.SchoolBasis = universityView.SchoolBasis;
universityProfile.SchoolMotto = universityView.SchoolMotto;
universityProfile.SubjectCount = universityView.SubjectCount;
universityProfile.Is211University = universityView.Is211University;
universityProfile.IsKeyUniversity = universityView.IsKeyUniversity;
universityProfile.IsAdultCollege = universityView.IsAdultCollege;
universityProfile.IsPostCollege = universityView.IsPostCollege;
universityProfile.IsNetCollege = universityView.IsNetCollege;
universityProfile.Telephone = universityView.Telephone;
universityProfile.ZIPCode = universityView.ZIPCode;
universityProfile.Email = universityView.Email;
universityProfile.FAX = universityView.FAX;
universityProfile.PublicNum = universityView.PublicNum;
universityProfile.HomePage = universityView.HomePage;
universityProfile.Address = universityView.Address;
universityProfile.EnglishAddress = universityView.EnglishAddress;
universityProfile.HistoryEvolution = universityView.HistoryEvolution;
SetModifyStatus(universityProfile);
}
}
}
else
{
//表示新增(CF_University主表)
CF_University university = new CF_University();
university.UniversityID = Guid.NewGuid();
university.Code = universityView.Code;
university.Name = universityView.Name;
university.SimpleName = universityView.SimpleName;
university.EnglishName = universityView.EnglishName;
university.Remark = universityView.Remark;
SetNewStatus(university);
UnitOfWork.Add(university);
//表示新增(CF_UniversityProfile扩展表)
CF_UniversityProfile universityProfile = new CF_UniversityProfile();
universityProfile.UniversityID = university.UniversityID;
universityProfile.ProvinceID = universityView.ProvinceID;
universityProfile.CityID = universityView.CityID;
universityProfile.DistrictID = universityView.DistrictID;
universityProfile.PropertyID = universityView.PropertyID;
universityProfile.SchoolTypeID = universityView.SchoolTypeID;
universityProfile.ManagerID = universityView.ManagerID;
universityProfile.FounderTypeID = universityView.FounderTypeID;
universityProfile.SchoolLevelID = universityView.SchoolLevelID;
universityProfile.HeadMasterName = universityView.HeadMasterName;
universityProfile.PartyManageID = universityView.PartyManageID;
universityProfile.LegalPersonName = universityView.LegalPersonName;
universityProfile.BuildDate = universityView.BuildDate;
universityProfile.AnniversaryDate = universityView.AnniversaryDate;
universityProfile.SchoolBasis = universityView.SchoolBasis;
universityProfile.SchoolMotto = universityView.SchoolMotto;
universityProfile.SubjectCount = universityView.SubjectCount;
universityProfile.Is211University = universityView.Is211University;
universityProfile.IsKeyUniversity = universityView.IsKeyUniversity;
universityProfile.IsAdultCollege = universityView.IsAdultCollege;
universityProfile.IsPostCollege = universityView.IsPostCollege;
universityProfile.IsNetCollege = universityView.IsNetCollege;
universityProfile.Telephone = universityView.Telephone;
universityProfile.ZIPCode = universityView.ZIPCode;
universityProfile.Email = universityView.Email;
universityProfile.FAX = universityView.FAX;
universityProfile.PublicNum = universityView.PublicNum;
universityProfile.HomePage = universityView.HomePage;
universityProfile.Address = universityView.Address;
universityProfile.EnglishAddress = universityView.EnglishAddress;
universityProfile.HistoryEvolution = universityView.HistoryEvolution;
SetNewStatus(universityProfile);
UnitOfWork.Add(universityProfile);
}
}
else
{
throw new Exception("已存在相同的学校代码或学校名称,请核查");
}
//事务提交
UnitOfWork.Commit();
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// 删除
///
///
///
public bool UniversityDelete(List universityIDList)
{
try
{
UnitOfWork.Delete(x => universityIDList.Contains(x.UniversityID));
UnitOfWork.Commit();
return true;
}
catch (Exception)
{
throw;
}
}
}
}