using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using Bowin.Common.Linq.Entity;
using EMIS.ViewModel;
using Bowin.Common.Linq;
using EMIS.Entities;
using EMIS.DataLogic.CultureplanManage.CourseMaterial;
using EMIS.ViewModel.Cultureplan;
using EMIS.ViewModel.CultureplanManage.CourseMaterial;
namespace EMIS.CommonLogic.CultureplanManage.CourseMaterial
{
public class ClubCourseServices : BaseServices, IClubCourseServices
{
public ClubCourseDAL ClubCourseDAL { get; set; }
///
/// 查询对应的俱乐部课程View
///
///
///
///
///
///
///
///
///
public IGridResultSet GetClubCourseViewGrid(ConfiguretView configuretView, int? courseLevelID, int? courseScienceID,
Guid? classGroupingID, int? isEnable, int pageIndex, int pageSize)
{
//俱乐部课程
Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
var query = ClubCourseDAL.GetClubCourseViewQueryable(exp);
if (courseLevelID.HasValue)
{
query = query.Where(x => x.CourseLevelID == courseLevelID);
}
if (courseScienceID.HasValue)
{
query = query.Where(x => x.CourseScienceID == courseScienceID);
}
if (classGroupingID.HasValue)
{
query = query.Where(x => x.ClassGroupingID == classGroupingID);
}
if (isEnable.HasValue)
{
if (isEnable == 1)
{
query = query.Where(x => x.IsEnable == true);
}
if (isEnable == 0)
{
query = query.Where(x => x.IsEnable != true);
}
}
//查询条件
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
{
query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
}
return query.OrderBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode)
.ToGridResultSet(pageIndex, pageSize);
}
///
/// 查询对应的俱乐部课程List
///
///
///
///
///
///
///
public List GetClubCourseViewList(ConfiguretView configuretView, int? courseLevelID, int? courseScienceID,
Guid? classGroupingID, int? isEnable)
{
//俱乐部课程
Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
var query = ClubCourseDAL.GetClubCourseViewQueryable(exp);
if (courseLevelID.HasValue)
{
query = query.Where(x => x.CourseLevelID == courseLevelID);
}
if (courseScienceID.HasValue)
{
query = query.Where(x => x.CourseScienceID == courseScienceID);
}
if (classGroupingID.HasValue)
{
query = query.Where(x => x.ClassGroupingID == classGroupingID);
}
if (isEnable.HasValue)
{
if (isEnable == 1)
{
query = query.Where(x => x.IsEnable == true);
}
if (isEnable == 0)
{
query = query.Where(x => x.IsEnable != true);
}
}
//查询条件
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
{
query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
}
return query.OrderBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode).ToList();
}
///
/// 查询对应的课程信息View(课程信息表左连俱乐部课程表,排除对应的俱乐部课程信息)
///
///
///
///
///
///
///
///
public IGridResultSet GetCourseNoClubViewGrid(ConfiguretView configuretView, int? courseLevelID,
int? courseScienceID, int? isEnable, int pageIndex, int pageSize)
{
//课程信息
Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
if (courseLevelID.HasValue)
{
//课程级别
exp = exp.And(x => x.CourseLevelID == courseLevelID);
}
if (courseScienceID.HasValue)
{
//课程科类
exp = exp.And(x => x.CourseScienceID == courseScienceID);
}
if (isEnable.HasValue)
{
if (isEnable == 1)
{
exp = exp.And(x => x.IsEnable == true);
}
if (isEnable == 0)
{
exp = exp.And(x => x.IsEnable != true);
}
}
var query = ClubCourseDAL.GetCourseNoClubViewQueryable(exp);
//查询条件
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
{
query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
}
return query.OrderBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode)
.ToGridResultSet(pageIndex, pageSize);
}
///
/// 查询对应的课程信息List(课程信息表左连俱乐部课程表,排除对应的俱乐部课程信息)
///
///
///
///
///
///
public List GetCourseNoClubViewList(ConfiguretView configuretView, int? courseLevelID, int? courseScienceID, int? isEnable)
{
//课程信息
Expression> exp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
if (courseLevelID.HasValue)
{
//课程级别
exp = exp.And(x => x.CourseLevelID == courseLevelID);
}
if (courseScienceID.HasValue)
{
//课程科类
exp = exp.And(x => x.CourseScienceID == courseScienceID);
}
if (isEnable.HasValue)
{
if (isEnable == 1)
{
exp = exp.And(x => x.IsEnable == true);
}
if (isEnable == 0)
{
exp = exp.And(x => x.IsEnable != true);
}
}
var query = ClubCourseDAL.GetCourseNoClubViewQueryable(exp);
//查询条件
if (!string.IsNullOrEmpty(configuretView.ConditionValue))
{
query = query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue.Trim());
}
return query.OrderBy(x => x.CourseCode.Length).ThenBy(x => x.CourseCode).ToList();
}
///
/// 根据俱乐部课程ID查询对应的俱乐部课程信息ClubCourseView
///
///
///
public ClubCourseView GetClubCourseView(Guid? ClubCourseID)
{
try
{
var query = ClubCourseDAL.GetClubCourseViewQueryable(x => x.ClubCourseID == ClubCourseID)
.SingleOrDefault();
return query;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// 批量新增
///
///
///
///
public string ClubCourseBatchAdd(ClubCourseView clubCourseView, List courseNoClubViewList)
{
try
{
//俱乐部课程信息List
var clubCourseList = ClubCourseDAL.ClubCourseRepository
.GetList(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE).ToList();
int success = 0; //成功
int fail = 0; //失败
string tipMessage = null; //提示消息
List clubCourseInList = new List();
foreach (var courseNoClubView in courseNoClubViewList)
{
//查询数据库进行验证
var clubCourseVerification = clubCourseList
.Where(x => x.CoursematerialID == courseNoClubView.CoursematerialID)
.SingleOrDefault();
if (clubCourseVerification == null)
{
//表示不存在对应的俱乐部课程(新增)
ER_ClubCourse clubCourse = new ER_ClubCourse();
clubCourse.ClubCourseID = Guid.NewGuid();
clubCourse.CoursematerialID = courseNoClubView.CoursematerialID;
SetNewStatus(clubCourse);
clubCourseInList.Add(clubCourse);
success++;
}
else
{
//表示已存在相同的俱乐部课程
fail++;
}
}
//批量插入
UnitOfWork.BulkInsert(clubCourseInList);
if (success > 0 && fail <= 0)
{
tipMessage = success + "条";
}
else
{
tipMessage = success + "条," + fail + "条失败,原因:已存在相同的俱乐部课程,请检查";
}
return tipMessage;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
///
/// 删除
///
///
///
public bool ClubCourseDelete(List clubCourseIDList)
{
try
{
UnitOfWork.Delete(x => clubCourseIDList.Contains(x.ClubCourseID));
UnitOfWork.Commit();
return true;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
}
}