using Edu.Common.Enum;
using Edu.Model.ViewModel.Course;
using Edu.Repository.Course;
using System.Collections.Generic;
using System.Linq;
using VT.FW.DB;
namespace Edu.Module.Course
{
///
/// 课程处理类
///
public class CourseModule
{
///
/// 课程章节仓储层对象
///
private readonly RB_Course_ChapterRepository chapterRepository = new RB_Course_ChapterRepository();
///
/// 课程讨论仓储层对象
///
private readonly RB_Course_DiscussRepository discussRepository = new RB_Course_DiscussRepository();
///
/// 课程通知仓储层对象
///
private readonly RB_Course_NoticeRepository noticeRepository = new RB_Course_NoticeRepository();
///
/// 课程通知接收仓储层对象
///
private readonly RB_Course_NoticeReviceRepository noticeReviceRepository = new RB_Course_NoticeReviceRepository();
///
/// 课程设置仓储层对象
///
private readonly RB_Course_SettingRepository settingRepository = new RB_Course_SettingRepository();
///
/// 课程资料仓储层对象
///
private readonly RB_Course_SourceRepository sourceRepository = new RB_Course_SourceRepository();
///
/// 课程教案仓储层对象
///
private readonly RB_Course_TeachPlanRepository teachPlanRepository = new RB_Course_TeachPlanRepository();
///
/// 课程处理仓储层对象
///
private readonly RB_CourseRepository courseRepository = new RB_CourseRepository();
///
/// 课程作业仓储层对象
///
private readonly RB_Course_JobRepository courseJobRepository = new RB_Course_JobRepository();
///
/// 课程分类处理类
///
private readonly CourseCategoryModule courseCategoryModule = new CourseCategoryModule();
///
/// 课程阶梯价格仓储层对象
///
private readonly RB_Course_StepPriceRepository course_StepPriceRepository = new RB_Course_StepPriceRepository();
#region 课程管理
///
/// 获取课程列表
///
///
///
public List GetCourseListModule(RB_Course_ViewModel query)
{
return courseRepository.GetCourseListRepository(query);
}
///
/// 获取课程分页列表
///
///
///
///
///
///
public List GetCoursePageListModule(int pageIndex, int pageSize, out long rowsCount, RB_Course_ViewModel query)
{
if (!string.IsNullOrWhiteSpace(query.QCateIds) && query.QCateIds != "0")
{
string cateIds = courseCategoryModule.GetChildCategoryStringModule(query.QCateIds);
if (!string.IsNullOrWhiteSpace(cateIds))
{
query.QCateIds = cateIds;
}
}
return courseRepository.GetCoursePageListRepository(pageIndex, pageSize, out rowsCount, query);
}
///
/// 根据课程编号获取课程实体
///
///
///
public RB_Course_ViewModel GetCourseModule(object CourseId)
{
var extModel= courseRepository.GetEntity(CourseId);
if (extModel != null && extModel.CourseId > 0)
{
var stepPriceList = course_StepPriceRepository.GetCourseStepPriceListRepository(new RB_Course_StepPrice_ViewModel()
{
CourseId = extModel.CourseId
});
extModel.StepPriceList = stepPriceList ?? new List();
}
return extModel;
}
///
/// 新增修改课程
///
///
public virtual bool SetCourseModule(RB_Course_ViewModel model)
{
bool flag;
if (model.IsRenew == 0)
{
model.RenewOgPrice = 0;
model.RenewSlPrice = 0;
}
if (model.CourseId > 0)
{
Dictionary fileds = new Dictionary()
{
{nameof(RB_Course_ViewModel.CoverImg),model.CoverImg },
{nameof(RB_Course_ViewModel.CourseName),model.CourseName },
{nameof(RB_Course_ViewModel.CourseIntro),model.CourseIntro },
{nameof(RB_Course_ViewModel.CateId),model.CateId },
{nameof(RB_Course_ViewModel.UpdateBy),model.UpdateBy },
{nameof(RB_Course_ViewModel.UpdateTime),model.UpdateTime },
{nameof(RB_Course_ViewModel.Teacher_Ids),model.Teacher_Ids },
{nameof(RB_Course_ViewModel.CourseFeature),model.CourseFeature },
{nameof(RB_Course_ViewModel.OriginalPrice),model.OriginalPrice },
{nameof(RB_Course_ViewModel.SellPrice),model.SellPrice },
{nameof(RB_Course_ViewModel.IsOpenStepPrice),model.IsOpenStepPrice },
{nameof(RB_Course_ViewModel.IsRenew),model.IsRenew },
{nameof(RB_Course_ViewModel.RenewOgPrice),model.RenewOgPrice },
{nameof(RB_Course_ViewModel.RenewSlPrice),model.RenewSlPrice },
{nameof(RB_Course_ViewModel.Saleplat),model.Saleplat },
{nameof(RB_Course_ViewModel.IsKCourse),model.IsKCourse },
};
flag = courseRepository.Update(fileds, new WhereHelper(nameof(RB_Course_ViewModel.CourseId), model.CourseId));
}
else
{
var newId = courseRepository.Insert(model);
model.CourseId = newId;
flag = newId > 0;
}
//没有设置阶梯价格,删除原来的价格
course_StepPriceRepository.DeleteStepPriceRepository(model.CourseId);
if (model.IsOpenStepPrice == 1)
{
if (model.StepPriceList != null && model.StepPriceList.Count > 0)
{
foreach (var item in model.StepPriceList)
{
item.CourseId = model.CourseId;
course_StepPriceRepository.Insert(item);
}
}
}
return flag;
}
///
/// 是否显示章节编号
///
///
/// 是否显示章节编号(1-显示,0-不显示)
///
public bool SetCourseIsShowChapterNoModule(int CourseId, int IsShowChapterNo)
{
Dictionary fileds = new Dictionary()
{
{nameof(RB_Course_ViewModel.IsShowChapterNo),IsShowChapterNo },
};
bool flag = courseRepository.Update(fileds, new WhereHelper(nameof(RB_Course_ViewModel.CourseId), CourseId));
return flag;
}
///
/// 设置课程教师
///
///
/// 教师编号
///
public bool SetCourseTeacherModule(int CourseId, int Teacher_Id)
{
Dictionary fileds = new Dictionary()
{
{nameof(RB_Course_ViewModel.Teacher_Ids),Teacher_Id },
};
bool flag = courseRepository.Update(fileds, new WhereHelper(nameof(RB_Course_ViewModel.CourseId), CourseId));
return flag;
}
///
/// 删除课程
///
///
///
public bool RemoveCourseModule(object CourseId)
{
Dictionary fileds = new Dictionary()
{
{nameof(RB_Course_ViewModel.Status),(int)DateStateEnum.Delete },
};
bool flag = courseRepository.Update(fileds, new WhereHelper(nameof(RB_Course_ViewModel.CourseId), CourseId));
return flag;
}
#endregion
#region 课程通知管理
///
/// 获取课程通知分页列表
///
///
///
///
///
///
public List GetNoticePageListModule(int pageIndex, int pageSize, out long rowsCount, RB_Course_Notice_ViewModel query)
{
return noticeRepository.GetNoticePageListRepository(pageIndex, pageSize, out rowsCount, query);
}
///
/// 新增修改课程通知
///
///
///
public bool SetNoticeModule(RB_Course_Notice_ViewModel model)
{
bool flag;
if (model.NoticeId > 0)
{
Dictionary fileds = new Dictionary()
{
{nameof(RB_Course_Notice_ViewModel.Title),model.Title }
};
flag = noticeRepository.Update(fileds, new WhereHelper(nameof(RB_Course_Notice_ViewModel.NoticeId), model.NoticeId));
}
else
{
var newId = noticeRepository.Insert(model);
model.NoticeId = newId;
flag = newId > 0;
}
return flag;
}
///
/// 获取课程通知实体
///
///
///
public RB_Course_Notice_ViewModel GetNoticeModule(object NoticeId)
{
return noticeRepository.GetEntity(NoticeId);
}
///
/// 根据通知编号删除通知
///
///
///
public bool RemoveNoticeModule(object NoticeId)
{
Dictionary fileds = new Dictionary()
{
{nameof(RB_Course_Notice_ViewModel.Status), (int)DateStateEnum.Delete}
};
bool flag = noticeRepository.Update(fileds, new WhereHelper(nameof(RB_Course_Notice_ViewModel.NoticeId), NoticeId));
return flag;
}
///
/// 新增通知阅读
///
///
///
public bool AddNoticeReviceModule(RB_Course_NoticeRevice_ViewModel model)
{
var newId = noticeReviceRepository.Insert(model);
model.ReviceId = newId;
return newId > 0;
}
#endregion
#region 课程章节管理
///
/// 获取课程章节列表
///
///
///
public List GetChapterListModule(RB_Course_Chapter_ViewModel query)
{
return chapterRepository.GetChapterListRepository(query);
}
///
/// 获取课程章节树形列表
///
///
///
public List GetChapterTreeListModule(RB_Course_Chapter_ViewModel query)
{
var list = GetChapterListModule(query);
List treeList = GetChapterChild(list, 0);
return treeList;
}
///
/// 递归遍历所有章节
///
/// 源数据
/// 父节点编号
///
public List GetChapterChild(List sourceList,int parentId)
{
List resultList = new List();
//获取下级节点
var subList = sourceList?.Where(qItem => qItem.ParentId==parentId).OrderBy(qitem=>qitem.SortNum).ToList();
//如果存在下级节点
if (subList != null&& subList.Count>0)
{
foreach (var childItem in subList)
{
var childModel = new ChapterTree_ViewModel()
{
ChapterId = childItem.ChapterId,
ParentId = childItem.ParentId,
ChapterContent = childItem.ChapterContent,
ChapterName = childItem.ChapterName,
ChapterNo = childItem.ChapterNo,
CourseId = childItem.CourseId,
ChildList = new List()
};
childModel.ChildList.AddRange(GetChapterChild(sourceList, childItem.ChapterId));
resultList.Add(childModel);
}
}
return resultList;
}
///
/// 新增修改课程章节
///
///
public bool SetChapterModule(RB_Course_Chapter_ViewModel model)
{
bool flag;
if (model.ChapterId > 0)
{
Dictionary fileds = new Dictionary()
{
{nameof(RB_Course_Chapter_ViewModel.ChapterNo) ,model.ChapterNo},
{nameof(RB_Course_Chapter_ViewModel.ChapterName) ,model.ChapterName},
{nameof(RB_Course_Chapter_ViewModel.ChapterContent) ,model.ChapterContent},
{nameof(RB_Course_Chapter_ViewModel.ParentId) ,model.ParentId},
};
flag = chapterRepository.Update(fileds, new WhereHelper(nameof(RB_Course_Chapter_ViewModel.ChapterId), model.ChapterId));
}
else
{
var newId = chapterRepository.Insert(model);
model.ChapterId = newId;
flag = newId > 0;
}
return flag;
}
///
/// 获取章节实体类
///
///
///
public RB_Course_Chapter_ViewModel GetChapterModule(object ChapterId)
{
return chapterRepository.GetEntity(ChapterId);
}
///
/// 删除章节
///
///
///
public bool RemoveChapterModule(object ChapterId)
{
Dictionary fileds = new Dictionary()
{
{nameof(RB_Course_Chapter_ViewModel.Status) ,(int)DateStateEnum.Delete},
};
bool flag = chapterRepository.Update(fileds, new WhereHelper(nameof(RB_Course_Chapter_ViewModel.ChapterId), ChapterId));
return flag;
}
///
/// 设置章节开发状态
///
///
///
public bool SetChapterOpenStatusModule(RB_Course_Chapter_ViewModel model)
{
Dictionary fileds = new Dictionary()
{
{nameof(RB_Course_Chapter_ViewModel.OpenStatus) ,model.OpenStatus},
{nameof(RB_Course_Chapter_ViewModel.OpenStart) ,model.OpenStart},
{nameof(RB_Course_Chapter_ViewModel.OpenEnd) ,model.OpenEnd},
};
bool flag = chapterRepository.Update(fileds, new WhereHelper(nameof(RB_Course_Chapter_ViewModel.ChapterId), model.ChapterId));
return flag;
}
///
/// 设置章节进度
///
///
///
///
public bool SetChapterProgressModule(object ChapterId, int Progress)
{
Dictionary fileds = new Dictionary()
{
{nameof(RB_Course_Chapter_ViewModel.Progress) ,Progress},
};
bool flag = chapterRepository.Update(fileds, new WhereHelper(nameof(RB_Course_Chapter_ViewModel.ChapterId), ChapterId));
return flag;
}
#endregion
#region 课程讨论管理
///
/// 获取课程讨论分页列表
///
///
///
///
///
///
public List GetDiscussPageListModule(int pageIndex, int pageSize, out long rowsCount, RB_Course_Discuss_ViewModel query)
{
return discussRepository.GetDiscussPageListRepository(pageIndex, pageSize, out rowsCount, query);
}
///
/// 新增修改讨论话题
///
///
///
public bool SetDiscussModule(RB_Course_Discuss_ViewModel model)
{
bool flag;
if (model.DiscussId > 0)
{
Dictionary fileds = new Dictionary()
{
{nameof(RB_Course_Discuss_ViewModel.DiscussTitle),model.DiscussTitle },
{nameof(RB_Course_Discuss_ViewModel.DiscussContent),model.DiscussContent },
{nameof(RB_Course_Discuss_ViewModel.DiscussUrl),model.DiscussUrl },
};
flag = discussRepository.Update(fileds, new WhereHelper(nameof(RB_Course_Discuss_ViewModel.DiscussId), model.DiscussId));
}
else
{
var newId = discussRepository.Insert(model);
model.DiscussId = newId;
flag = newId > 0;
}
return flag;
}
///
/// 获取讨论话题
///
///
///
public RB_Course_Discuss_ViewModel GetDiscussModule(object DiscussId)
{
return discussRepository.GetEntity(DiscussId);
}
///
/// 删除讨论话题
///
///
///
public bool RemoveDiscussModule(object DiscussId)
{
Dictionary fileds = new Dictionary()
{
{nameof(RB_Course_Discuss_ViewModel.Status),(int)DateStateEnum.Delete },
};
bool flag = discussRepository.Update(fileds, new WhereHelper(nameof(RB_Course_Discuss_ViewModel.DiscussId), DiscussId));
return flag;
}
#endregion
#region 课程配置
///
/// 新增修改课程配置
///
///
///
public bool SetCourseSettingModule(RB_Course_Setting_ViewModel model)
{
var oldModel = settingRepository.GetCourseSettingRepository(model);
bool flag;
if (oldModel != null && oldModel.SettingId > 0)
{
Dictionary fileds = new Dictionary()
{
{nameof(RB_Course_Setting_ViewModel.AppIsCache),model.AppIsCache },
{nameof(RB_Course_Setting_ViewModel.PlayType),model.PlayType },
};
flag = settingRepository.Update(fileds, new WhereHelper(nameof(RB_Course_Setting_ViewModel.SettingId), oldModel.SettingId));
}
else
{
var newId = settingRepository.Insert(model);
model.SettingId = newId;
flag = newId > 0;
}
return flag;
}
#endregion
#region 课程资料管理
///
/// 获取课程资料分页列表
///
///
///
///
///
///
public List GetSourcePageListModule(int pageIndex, int pageSize, out long rowsCount, RB_Course_Source_ViewModel query)
{
return sourceRepository.GetSourcePageListRepository(pageIndex, pageSize, out rowsCount, query);
}
///
/// 新增修改课程资料
///
///
///
public bool SetCourseSourceModule(RB_Course_Source_ViewModel model)
{
bool flag;
if (model.SourceId > 0)
{
Dictionary fileds = new Dictionary()
{
{nameof(RB_Course_Source_ViewModel.SourceName),model.SourceName },
{nameof(RB_Course_Source_ViewModel.SourceType),model.SourceType },
{nameof(RB_Course_Source_ViewModel.SourceUrl),model.SourceUrl },
{nameof(RB_Course_Source_ViewModel.SourceSize),model.SourceSize },
{nameof(RB_Course_Source_ViewModel.ParentSourceId),model.ParentSourceId },
};
flag = sourceRepository.Update(fileds, new WhereHelper(nameof(RB_Course_Source_ViewModel.SourceId), model.SourceId));
}
else
{
var newId = sourceRepository.Insert(model);
model.SourceId = newId;
flag = newId > 0;
}
return flag;
}
///
/// 根据编号获取课程资料实体
///
///
///
public RB_Course_Source_ViewModel GetCourseSourceModule(object SourceId)
{
return sourceRepository.GetEntity(SourceId);
}
///
/// 更新资料共享类型
///
///
/// 共享类型
///
public bool SetCourseSourceShareTypeModule(object SourceId, int ShareType)
{
Dictionary fileds = new Dictionary()
{
{nameof(RB_Course_Source_ViewModel.ShareType),ShareType},
};
bool flag = sourceRepository.Update(fileds, new WhereHelper(nameof(RB_Course_Source_ViewModel.SourceId), SourceId));
return flag;
}
///
/// 根据编号删除课程资料
///
///
///
public bool RemoveCourseSourceModule(object SourceId)
{
Dictionary fileds = new Dictionary()
{
{nameof(RB_Course_Source_ViewModel.Status),(int)DateStateEnum.Delete},
};
bool flag = sourceRepository.Update(fileds, new WhereHelper(nameof(RB_Course_Source_ViewModel.SourceId), SourceId));
return flag;
}
#endregion
#region 课程教案管理
///
/// 获取课程教案分页列表
///
///
///
///
///
///
public List GetCourseTeachPlanPageListModule(int pageIndex, int pageSize, out long rowsCount, RB_Course_TeachPlan_ViewModel query)
{
return teachPlanRepository.GetCourseTeachPlanPageListRepository(pageIndex, pageSize, out rowsCount, query);
}
///
/// 添加修改课程教案
///
///
///
public bool SetTeachPlanModule(RB_Course_TeachPlan_ViewModel model)
{
bool flag;
if (model.PlanId > 0)
{
Dictionary fileds = new Dictionary()
{
{nameof(RB_Course_TeachPlan_ViewModel.PlanName),model.PlanName },
{nameof(RB_Course_TeachPlan_ViewModel.ClassBefore),model.ClassBefore },
{nameof(RB_Course_TeachPlan_ViewModel.ClassIn),model.ClassIn },
{nameof(RB_Course_TeachPlan_ViewModel.ClassAfter),model.ClassAfter },
{nameof(RB_Course_TeachPlan_ViewModel.ParentPlanId),model.ParentPlanId },
{nameof(RB_Course_TeachPlan_ViewModel.SourceUrl),model.SourceUrl },
{nameof(RB_Course_TeachPlan_ViewModel.PlanFileExtension),model.PlanFileExtension },
{nameof(RB_Course_TeachPlan_ViewModel.PlanNodeType),model.PlanNodeType },
{nameof(RB_Course_TeachPlan_ViewModel.ExtUrl),model.ExtUrl },
{nameof(RB_Course_TeachPlan_ViewModel.Remark),model.Remark },
{nameof(RB_Course_TeachPlan_ViewModel.IsTop),model.IsTop },
};
flag = teachPlanRepository.Update(fileds, new WhereHelper(nameof(RB_Course_TeachPlan_ViewModel.PlanId), model.PlanId));
}
else
{
var newId = teachPlanRepository.Insert(model);
model.PlanId = newId;
flag = newId > 0;
}
return flag;
}
///
/// 根据编号获取教案实体
///
///
///
public RB_Course_TeachPlan_ViewModel GetTeachPlanModule(object PlanId)
{
return teachPlanRepository.GetEntity(PlanId);
}
///
/// 删除教案
///
///
///
public bool RemoveTeachPlanModule(object PlanId)
{
Dictionary fileds = new Dictionary()
{
{nameof(RB_Course_TeachPlan_ViewModel.Status),(int)DateStateEnum.Delete },
};
bool flag = teachPlanRepository.Update(fileds, new WhereHelper(nameof(RB_Course_TeachPlan_ViewModel.PlanId), PlanId));
return flag;
}
#endregion
#region 课程作业管理
///
/// 新增修改课程作业
///
///
///
public bool SetCourseJobModule(RB_Course_Job_ViewModel model)
{
bool flag;
if (model.JobId > 0)
{
Dictionary fileds = new Dictionary()
{
{nameof(RB_Course_Job_ViewModel.JobName),model.JobName },
{nameof(RB_Course_Job_ViewModel.ScoreType),model.ScoreType },
{nameof(RB_Course_Job_ViewModel.TopicType),model.TopicType },
{nameof(RB_Course_Job_ViewModel.ReciveClass),model.ReciveClass },
{nameof(RB_Course_Job_ViewModel.StartTime),model.StartTime },
{nameof(RB_Course_Job_ViewModel.EndTime),model.EndTime },
{nameof(RB_Course_Job_ViewModel.IsAllowDelay),model.IsAllowDelay },
{nameof(RB_Course_Job_ViewModel.PassBasicScore),model.PassBasicScore },
{nameof(RB_Course_Job_ViewModel.IsAgain),model.IsAgain },
{nameof(RB_Course_Job_ViewModel.AgainTimes),model.AgainTimes },
{nameof(RB_Course_Job_ViewModel.IsGetHighScore),model.IsGetHighScore },
{nameof(RB_Course_Job_ViewModel.IsLookAnswer),model.IsLookAnswer },
{nameof(RB_Course_Job_ViewModel.LookAnswerType),model.LookAnswerType },
{nameof(RB_Course_Job_ViewModel.IsLookScore),model.IsLookScore },
{nameof(RB_Course_Job_ViewModel.IsLookQTypeScore),model.IsLookQTypeScore },
{nameof(RB_Course_Job_ViewModel.IsPaste),model.IsPaste },
{nameof(RB_Course_Job_ViewModel.IsAgainShowTrueFalse),model.IsAgainShowTrueFalse },
{nameof(RB_Course_Job_ViewModel.IsOutOrder),model.IsOutOrder },
{nameof(RB_Course_Job_ViewModel.IsRandom),model.IsRandom },
{nameof(RB_Course_Job_ViewModel.RandomNum),model.RandomNum },
{nameof(RB_Course_Job_ViewModel.IsSendMsg),model.IsSendMsg },
{nameof(RB_Course_Job_ViewModel.SendMsgHour),model.SendMsgHour },
{nameof(RB_Course_Job_ViewModel.IsWork),model.IsWork },
{nameof(RB_Course_Job_ViewModel.WorkProcess),model.WorkProcess },
{nameof(RB_Course_Job_ViewModel.IsBlankobj),model.IsBlankobj },
{nameof(RB_Course_Job_ViewModel.IsCompletionIngoreCase),model.IsCompletionIngoreCase },
{nameof(RB_Course_Job_ViewModel.IsBlankIgnoreComma),model.IsBlankIgnoreComma },
{nameof(RB_Course_Job_ViewModel.IsMultiHalfScore),model.IsMultiHalfScore },
};
flag = courseJobRepository.Update(fileds, new WhereHelper(nameof(RB_Course_Job_ViewModel.JobId), model.JobId));
}
else
{
var newId = courseJobRepository.Insert(model);
model.JobId = newId;
flag = newId > 0;
}
return flag;
}
#endregion
}
}