using System; using System.Collections.Generic; using System.Linq; using System.Text; using EMISOnline.Entities; using EMISOnline.DataLogic.Educational; using EMISOnline.ViewModel.Educational; using Bowin.Common.Linq.Entity; using Bowin.Common.Linq; using System.Linq.Expressions; using System.Web.Script.Serialization; using EMISOnline.ViewModel; namespace EMISOnline.CommonLogic.EducationalServices { public class CourseBuildServices : BaseServices, ICourseBuildServices { public CourseDAL CourseDAL { get; set; } public CourseBuildDAL CourseBuildDAL { get; set; } public IGridResultSet GetCoursematerList(int pageIndex, int pageSize, string courseName, string CourseCode) { Expression> exp = (e => true); if (!string.IsNullOrEmpty(courseName)) { exp = exp.And(e => e.CourseName.Contains(courseName.Trim())); } if (!string.IsNullOrEmpty(CourseCode)) { exp = exp.And(e => e.CourseCode.Contains(CourseCode.Trim())); } var list = CourseDAL.GetCourseList().Where(exp).OrderByDescending(r => r.CreateTime).ToGridResultSet(pageIndex, pageSize); return list; } public IGridResultSet GetCourseChapterList(int pageIndex, int pageSize, string chapterName, Guid? CoursematerialID) { Expression> exp = (e => true); if (!string.IsNullOrEmpty(chapterName)) { exp = exp.And(e => e.Name.Contains(chapterName.Trim())); } if (CoursematerialID.HasValue) { exp = exp.And(e => e.CoursematerialID == CoursematerialID); } var list = CourseBuildDAL.GetCourseChapterList().Where(exp).OrderByDescending(r => r.CreateTime).ToGridResultSet(pageIndex, pageSize); return list; } public IList GetCourseChapterList(Guid? CoursematerialID) { Expression> exp = (e => true); if (CoursematerialID.HasValue) { exp = exp.And(e => e.CoursematerialID == CoursematerialID); } var list = CourseBuildDAL.GetCourseChapterList().Where(exp).OrderBy(r => r.OrderID).ToList(); return list; } public IGridResultSet GetChaperVideoList(Guid? CourseChapterID) { Expression> exp = (e => true); if (CourseChapterID.HasValue) { exp = exp.And(e => e.CourseChapterID == CourseChapterID); } var list = CourseBuildDAL.GetChaperVideoList().Where(exp).OrderBy(r => r.CreateTime).ToList(); var result = new GridResultSet { rows = list }; result.total = list.Count; return result; } public IGridResultSet GetVideoList(int pageIndex, int pageSize, string videoName) { Expression> exp = (e => true); if (!string.IsNullOrEmpty(videoName)) { exp = exp.And(e => e.Name.Contains(videoName.Trim())); } var list = CourseBuildDAL.GetVideoList().Where(exp).OrderByDescending(r => r.CreateTime).ToGridResultSet(pageIndex, pageSize); return list; } public void AddChapter(Guid? ParentCourseChapterID, Guid? CourseChapterID, string Name, int? OrderID, int VideoTypeID, Guid? CourseVideoID, string OuterVideoUrl, Guid CoursematerialID) { EM_CourseChapter chapter = new EM_CourseChapter(); if (CourseChapterID.HasValue && CourseChapterID != Guid.Empty)//修改 { chapter = CourseBuildDAL.GetChapterSingle(CourseChapterID.Value); chapter.ParentCourseChapterID = ParentCourseChapterID; chapter.Name = Name; chapter.OrderID = OrderID; chapter.CoursematerialID = CoursematerialID; chapter.VideoTypeID = VideoTypeID; chapter.OuterVideoUrl = OuterVideoUrl; UnitOfWork.Update(chapter); } else//新增 { chapter.CourseChapterID = Guid.NewGuid(); chapter.ParentCourseChapterID = ParentCourseChapterID; chapter.Name = Name; chapter.OrderID = OrderID; chapter.CreateTime = DateTime.Now; chapter.CoursematerialID = CoursematerialID; chapter.VideoTypeID = VideoTypeID; chapter.OuterVideoUrl = OuterVideoUrl; chapter.RecordStatus = 1; UnitOfWork.Add(chapter); } if (CourseVideoID.HasValue && VideoTypeID == (int)EM_OnlineVideoType.Local) { CourseBuildDAL.DelChapterVideo(chapter.CourseChapterID); EM_CourseChapter_Video chapterVideo = new EM_CourseChapter_Video(); chapterVideo.CourseChapterID = chapter.CourseChapterID; chapterVideo.CourseVideoID = CourseVideoID.Value; UnitOfWork.Add(chapterVideo); } UnitOfWork.Commit(); } public void DeleteChapter(Guid CourseChapterID) { CourseBuildDAL.DelChapter(CourseChapterID); UnitOfWork.Commit(); } public bool IsAnySubChapter(Guid ParentCourseChapterID) { return CourseBuildDAL.IsAnySubChapter(ParentCourseChapterID); } } }