PlayController.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. using System.Threading.Tasks;
  2. using System.Web.Mvc;
  3. using System.Web.WebPages;
  4. using Abp.Web.Mvc.Authorization;
  5. using WeOnlineApp.BaseSystem.Query;
  6. using WeOnlineApp.Configuration;
  7. using WeOnlineApp.Models.Play;
  8. using WeOnlineApp.TrainingCampPlay;
  9. namespace WeOnlineApp.Controllers
  10. {
  11. [AbpMvcAuthorize]
  12. public class PlayController : IwbControllerBase
  13. {
  14. public PlayController(CampPlayAppService playApp, QueryAppService queryApp)
  15. {
  16. PlayApp = playApp;
  17. QueryApp = queryApp;
  18. }
  19. public CampPlayAppService PlayApp { get; }
  20. public QueryAppService QueryApp { get; }
  21. [AbpMvcAuthorize]
  22. public ActionResult Index()
  23. {
  24. CheckAccount();
  25. return View();
  26. }
  27. [AbpMvcAuthorize]
  28. public async Task<ActionResult> Start()
  29. {
  30. CheckAccount();
  31. var playNo = await PlayApp.GetRunPlay();
  32. if (playNo.IsEmpty())
  33. {
  34. return RedirectToAction("PlayList");
  35. }
  36. return RedirectToAction("Ready", new { id = playNo });
  37. }
  38. [AbpMvcAuthorize]
  39. public async Task<ActionResult> Ready(string id)
  40. {
  41. CheckAccount();
  42. if (id.IsEmpty())
  43. {
  44. id = await PlayApp.GetRunPlay();
  45. }
  46. if (id.IsEmpty())
  47. {
  48. CheckErrors("未查询到您正在演练,请选择一个演练加入或自己创建一个演练再开始!");
  49. }
  50. var play = await QueryApp.QueryPlay(id);
  51. if (play == null)
  52. {
  53. CheckErrors("未查询到演练,无法加入!");
  54. return View();
  55. }
  56. var playUser = await PlayApp.GetPlayUser(play.Id);
  57. if (play.PlayModel == CampPlayModelDefinition.Single)
  58. {
  59. if (playUser == null)
  60. {
  61. CheckErrors("单人演练,其他人无法加入!");
  62. }
  63. }
  64. else if ((!await PlayApp.CheckIsRun(id)) && !play.IsPublic)
  65. {
  66. //CheckErrors("演练未公开,无法加入!");
  67. return View("Code");
  68. }
  69. CampPlayModel campPlay = new CampPlayModel()
  70. {
  71. Play = play,
  72. Camp = await QueryApp.QueryCamp(play.CampNo),
  73. PlayUser = playUser
  74. };
  75. ViewBag.CampPlay = campPlay;
  76. if (play.PlayState == CampPlayStateDefinition.New)
  77. {
  78. return View("_Run/Ready", campPlay);
  79. }
  80. return View("_Run/Run", campPlay);
  81. //return View("Run", campPlay);
  82. }
  83. [AllowAnonymous]
  84. [AccessOriginal]
  85. public async Task<ActionResult> Display(string id)
  86. {
  87. var play = await QueryApp.QueryPlay(id);
  88. var playUser = await PlayApp.GetPlayUser(play.Id);
  89. CampPlayModel campPlay = new CampPlayModel()
  90. {
  91. Play = play,
  92. Camp = await QueryApp.QueryCamp(play.CampNo),
  93. PlayUser = playUser
  94. };
  95. ViewBag.CampPlay = campPlay;
  96. return View("_Run/Display", campPlay);
  97. }
  98. public ActionResult Code()
  99. {
  100. return View();
  101. }
  102. public async Task<ActionResult> Run(string id)
  103. {
  104. if (id.IsEmpty())
  105. {
  106. CheckErrors("未查询演练,请重新选择一个演练加入或自己创建一个演练再开始!");
  107. }
  108. var play = await PlayApp.GetPlayByCode(id);
  109. if (play == null)
  110. {
  111. CheckErrors("未查询到演练,无法加入!");
  112. return View("Index");
  113. }
  114. CampPlayModel campPlay = new CampPlayModel()
  115. {
  116. Play = play,
  117. Camp = await QueryApp.QueryCamp(play.CampNo),
  118. PlayUser = await PlayApp.GetPlayUser(play.Id)
  119. };
  120. ViewBag.CampPlay = campPlay;
  121. if (play.PlayState == CampPlayStateDefinition.New)
  122. {
  123. return View("_Run/Ready", campPlay);
  124. }
  125. return View("_Run/Run", campPlay);
  126. //return View();
  127. }
  128. [AbpMvcAuthorize]
  129. public ActionResult PlayList()
  130. {
  131. CheckAccount();
  132. return View();
  133. }
  134. [AbpMvcAuthorize]
  135. public async Task<ActionResult> Create(string id)
  136. {
  137. CheckAccount();
  138. if (id.IsEmpty())
  139. {
  140. CheckErrors("课程编号不能为空!");
  141. }
  142. ViewBag.PageId = "start";
  143. ViewBag.Camp = await QueryApp.QueryCamp(id);
  144. return View();
  145. }
  146. [AbpMvcAuthorize]
  147. public async Task<ActionResult> Detail(string id)
  148. {
  149. CheckAccount();
  150. if (id.IsEmpty())
  151. {
  152. CheckErrors("课程编号不能为空!");
  153. }
  154. ViewBag.PageId = "start";
  155. ViewBag.Camp = await QueryApp.QueryCamp(id);
  156. return View();
  157. }
  158. [AbpMvcAuthorize]
  159. public async Task<ActionResult> DetailByPlay(string id)
  160. {
  161. CheckAccount();
  162. if (id.IsEmpty())
  163. {
  164. CheckErrors("课程编号不能为空!");
  165. }
  166. ViewBag.PageId = "start";
  167. ViewBag.Camp = await QueryApp.QueryCampByPlay(id);
  168. return View("Detail");
  169. }
  170. public async Task<ActionResult> Study(string id)
  171. {
  172. CheckAccount();
  173. ViewBag.Camp = await QueryApp.QueryCampWithStudy(id);
  174. return View();
  175. }
  176. public ActionResult History()
  177. {
  178. CheckAccount();
  179. return View();
  180. }
  181. public ActionResult Medal()
  182. {
  183. CheckAccount();
  184. return View();
  185. }
  186. public ActionResult Team()
  187. {
  188. CheckAccount();
  189. return View();
  190. }
  191. public async Task<ActionResult> Report(string id)
  192. {
  193. CheckAccount();
  194. if (id.IsEmpty())
  195. {
  196. CheckErrors("演练编号不能为空!");
  197. }
  198. var play = await PlayApp.GetReportPlay(id);
  199. if (play == null)
  200. {
  201. CheckErrors("未查询到演练!");
  202. }
  203. ViewBag.Play = play;
  204. return View();
  205. }
  206. }
  207. }