CourseBuildController.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using EMISOnline.CommonLogic.EducationalServices;
  7. using Bowin.Web.Controls.Mvc;
  8. using EMISOnline.ViewModel.Educational;
  9. using EMISOnline.ViewModel;
  10. namespace EMISOnline.Web.Controllers.Manage
  11. {
  12. public class CourseBuildController : Controller
  13. {
  14. //课程建设
  15. public ICourseBuildServices ICourseBuildServices { get; set; }
  16. public ActionResult List()
  17. {
  18. return View();
  19. }
  20. [HttpPost]
  21. public ActionResult List(int page, int rows, string CourseName, string CourseCode)
  22. {
  23. var result = ICourseBuildServices.GetCoursematerList(page, rows, CourseName, CourseCode);
  24. return Json(result);
  25. }
  26. public ActionResult ChapterList(Guid CoursematerialID)
  27. {
  28. ViewBag.CoursematerialID = CoursematerialID;
  29. ViewBag.DefaultVideoTypeID = (int)EMISOnline.ViewModel.EM_OnlineVideoType.Local;
  30. return View();
  31. }
  32. [HttpPost]
  33. public ActionResult ChapterList(Guid? ParentCourseChapterID, Guid? CourseChapterID, string Name, int? OrderID,
  34. int VideoTypeID, Guid? CourseVideoID, string OuterVideoUrl,
  35. Guid CoursematerialID, int type)
  36. {
  37. if (type == 1)
  38. {
  39. try
  40. {
  41. ICourseBuildServices.AddChapter(ParentCourseChapterID, CourseChapterID, Name, OrderID, VideoTypeID,
  42. CourseVideoID, OuterVideoUrl, CoursematerialID);
  43. return Json(new ReturnMessage()
  44. {
  45. IsSuccess = true,
  46. Message = "保存成功!"
  47. });
  48. }
  49. catch (Exception ex)
  50. {
  51. return Json(new ReturnMessage()
  52. {
  53. IsSuccess = false,
  54. Message = "保存失败:" + ex.Message
  55. });
  56. }
  57. }
  58. else
  59. {
  60. try
  61. {
  62. if (ICourseBuildServices.IsAnySubChapter(CourseChapterID.Value))
  63. {
  64. return Json(new ReturnMessage()
  65. {
  66. IsSuccess = false,
  67. Message = "删除失败:请先删除子章节!"
  68. });
  69. }
  70. else
  71. {
  72. ICourseBuildServices.DeleteChapter(CourseChapterID.Value);
  73. return Json(new ReturnMessage()
  74. {
  75. IsSuccess = true,
  76. Message = "删除成功!"
  77. });
  78. }
  79. }
  80. catch (Exception ex)
  81. {
  82. return Json(new ReturnMessage()
  83. {
  84. IsSuccess = false,
  85. Message = "删除失败:" + ex.Message
  86. });
  87. }
  88. }
  89. }
  90. [HttpPost]
  91. public ActionResult ChaperVideoList(Guid CourseChapterID)
  92. {
  93. var result = ICourseBuildServices.GetChaperVideoList(CourseChapterID);
  94. return Json(result);
  95. }
  96. [HttpPost]
  97. public ActionResult GetChaperVideo(Guid CourseChapterID)
  98. {
  99. var model = new CourseVideoView();
  100. try
  101. {
  102. model = ICourseBuildServices.GetChaperVideoList(CourseChapterID).rows.FirstOrDefault();
  103. }
  104. catch { }
  105. return Json(model);
  106. }
  107. public ActionResult Edit(Guid CourseChapterID)
  108. {
  109. return View();
  110. }
  111. [HttpPost]
  112. public ActionResult GetChaperTree(Guid CoursematerialID)
  113. {
  114. var tree = new List<TreeItem>();
  115. tree.Add(new TreeItem() { id = "", text = "顶层" });
  116. var allChaper = ICourseBuildServices.GetCourseChapterList(CoursematerialID);
  117. tree[0].children = allChaper.Where(r => r.ParentCourseChapterID == null).OrderBy(x => x.OrderID)
  118. .Select(x => new TreeItem
  119. {
  120. id = x.CourseChapterID.ToString(),
  121. text = x.Name,
  122. attributes = new ChaperTree { parentId = "", orderId = x.OrderID, videoTypeID = x.VideoTypeID, outerVideoUrl = x.OuterVideoUrl }
  123. }).ToList();
  124. tree[0].children.ForEach(x => BindChaperTreeChildren(allChaper, x));
  125. return Json(tree);
  126. }
  127. private void BindChaperTreeChildren(IList<CourseChapterView> allChapter, TreeItem treeItem)
  128. {
  129. try
  130. {
  131. treeItem.children = allChapter.Where(x => x.ParentCourseChapterID != null && x.ParentCourseChapterID.Value.ToString() == treeItem.id)
  132. .OrderBy(x => x.OrderID)
  133. .Select(x => new TreeItem
  134. {
  135. id = x.CourseChapterID.ToString(),
  136. text = x.Name,
  137. attributes = new ChaperTree { parentId = x.ParentCourseChapterID.Value.ToString(), orderId = x.OrderID, videoTypeID = x.VideoTypeID, outerVideoUrl = x.OuterVideoUrl }
  138. }).ToList();
  139. }
  140. catch (Exception ex)
  141. {
  142. throw ex;
  143. }
  144. treeItem.children.ForEach(x => BindChaperTreeChildren(allChapter, x));
  145. }
  146. [HttpPost]
  147. public ActionResult GetVideoList(int page, int rows, string Name)
  148. {
  149. var result = ICourseBuildServices.GetVideoList(page - 1, rows, Name);
  150. return Json(result);
  151. }
  152. }
  153. }