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 CourseCategoryModule { /// /// 课程分类仓储对象 /// private readonly RB_Course_CategoryRepository categoryRepository = new RB_Course_CategoryRepository(); /// /// 获取课程分类列表 /// /// /// public List GetCourseCategoryListModule(RB_Course_Category_ViewModel query) { return categoryRepository.GetCourseCategoryListRepository(query); } /// /// 获取课程分类分页列表 /// /// /// /// /// /// public List GetCourseCategoryPageListModule(int pageIndex, int pageSize, out long rowsCount, RB_Course_Category_ViewModel query) { return categoryRepository.GetCourseCategoryPageListRepository(pageIndex, pageSize, out rowsCount, query); } /// /// 获取当前和当前所有下级分类列表 /// /// 事例(1,5) /// public List GetChildCategoryListModule(string cateIds) { return categoryRepository.GetChildCategoryListRepository(cateIds); } /// /// 获取当前和当前所有下级分类编号 /// /// 事例(1,5) /// public string GetChildCategoryStringModule(string cateIds) { string result = ""; var list = GetChildCategoryListModule(cateIds); if (list != null && list.Count > 0) { result = string.Join(",", list.Select(qitem => qitem.CateId)); } return result; } /// /// 根据分类编号获取课程分类实体 /// /// /// public RB_Course_Category_ViewModel GetCourseCategoryModule(object CateId) { return categoryRepository.GetEntity(CateId); } /// /// 获取课程分类树形列表 /// /// /// public List GetCourseCategoryTreeListModule(RB_Course_Category_ViewModel query) { List treeList = new List(); var list = GetCourseCategoryListModule(query); if (list != null && list.Count > 0) { var firstList = list.Where(qitem => qitem.ParentId == 0).ToList(); if (firstList != null && firstList.Count > 0) { foreach (var fItem in firstList) { CourseCategoryTree_ViewModel tModel = new CourseCategoryTree_ViewModel() { CateId = fItem.CateId, CateName = fItem.CateName, ParentId = fItem.ParentId, ChildList = new List() }; tModel.ChildList = GetCategoryTreeList(fItem.CateId, list); treeList.Add(tModel); } } } return treeList; } /// /// 递归生成树形结构 /// /// 父节点编号 /// 数据源列表 private List GetCategoryTreeList(int parentId, List sourceList) { List treeList = new List(); foreach (var item in sourceList.Where(qitem => qitem.ParentId == parentId)) { CourseCategoryTree_ViewModel model = new CourseCategoryTree_ViewModel() { CateId = item.CateId, CateName = item.CateName, ParentId = item.ParentId, ChildList = new List(), }; model.ChildList = GetCategoryTreeList(item.CateId, sourceList); treeList.Add(model); } return treeList; } /// /// 新增修改课程分类 /// /// /// public bool SetCourseCategoryModule(RB_Course_Category_ViewModel model) { bool flag; if (model.CateId > 0) { Dictionary fileds = new Dictionary() { {nameof(RB_Course_Category_ViewModel.ParentId),model.ParentId }, {nameof(RB_Course_Category_ViewModel.CateName),model.CateName.Trim() }, {nameof(RB_Course_Category_ViewModel.SortNum),model.SortNum }, {nameof(RB_Course_Category_ViewModel.UpdateBy),model.UpdateBy }, {nameof(RB_Course_Category_ViewModel.UpdateTime),model.UpdateTime }, }; flag = categoryRepository.Update(fileds, new WhereHelper(nameof(RB_Course_Category_ViewModel.CateId), model.CateId)); } else { var newId = categoryRepository.Insert(model); model.CateId = newId; flag = newId > 0; } return flag; } /// /// 根据分类编号删除课程分类 /// /// /// public bool RemoveCourseCategoryModule(int CateId) { Dictionary fileds = new Dictionary() { {nameof(RB_Course_Category_ViewModel.Status),(int)DateStateEnum.Delete }, }; bool flag = categoryRepository.Update(fileds, new WhereHelper(nameof(RB_Course_Category_ViewModel.CateId), CateId)); return flag; } } }