PlayController.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using System.Threading.Tasks;
  2. using System.Web.Mvc;
  3. using Abp.Auditing;
  4. using Abp.Authorization;
  5. using Abp.Domain.Repositories;
  6. using IwbZero.ToolCommon.StringModel;
  7. using WeApp.BaseSystem.Query;
  8. using WeApp.Configuration;
  9. using WeApp.TrainingCamp;
  10. using WeApp.TrainingCamp.Dto;
  11. using WeApp.Views.Shared.Camp;
  12. namespace WeApp.Controllers
  13. {
  14. /// <summary>
  15. /// 演练实施
  16. /// </summary>
  17. [AbpAllowAnonymous, DisableAuditing]
  18. public class PlayController : IwbControllerBase
  19. {
  20. protected IRepository<CampInfo, string> CampRepository { get; }
  21. protected QueryAppService QueryApp { get; }
  22. private int TimeOut = 60 * 5;
  23. public PlayController(QueryAppService queryApp, IRepository<CampInfo, string> campRepository)
  24. {
  25. QueryApp = queryApp;
  26. CampRepository = campRepository;
  27. }
  28. /// <summary>
  29. /// 主屏页面
  30. /// </summary>
  31. /// <param name="id"></param>
  32. /// <returns></returns>
  33. public async Task<ActionResult> Index(string id)
  34. {
  35. CampInfo camp;
  36. if (id == "1")
  37. {
  38. camp = await CampRepository.FirstOrDefaultAsync(a => a.CampState == CampStateDefinition.Run);
  39. if (camp == null)
  40. {
  41. CheckErrors("未查询到正在运行的培训营!");
  42. return Content("Error");
  43. }
  44. }
  45. else
  46. {
  47. string campNo = id.IsEmpty() ? (string)Session["CampNo"] : id;
  48. if (campNo.IsEmpty())
  49. {
  50. TempData[ExerciseController.SelectDataKey] = new SelectCampModel
  51. {
  52. PageUrl = "/Play/Index",
  53. PageTitle = "演示屏选择培训营",
  54. HasGroup = false
  55. };
  56. return RedirectToAction("SelectCamp", "Exercise");
  57. }
  58. camp = await CampRepository.FirstOrDefaultAsync(a => a.Id == campNo);
  59. if (camp == null)
  60. {
  61. CheckErrors($"未查到到编号为【{campNo}】的培训营!");
  62. return null;
  63. }
  64. Session["CampNo"] = campNo;
  65. Session.Timeout = TimeOut;
  66. }
  67. ViewBag.Camp = ObjectMapper.Map<CampDto>(camp);
  68. if (camp.CampState != CampStateDefinition.Run)
  69. {
  70. return View("Wait");
  71. }
  72. ViewBag.Groups = await QueryApp.GetCampGroups(id);
  73. return View();
  74. }
  75. /// <summary>
  76. /// 主屏页面
  77. /// </summary>
  78. /// <param name="id"></param>
  79. /// <returns></returns>
  80. public async Task<ActionResult> IndexWithScore(string id)
  81. {
  82. CampInfo camp;
  83. if (id == "1")
  84. {
  85. camp = await CampRepository.FirstOrDefaultAsync(a => a.CampState == CampStateDefinition.Run);
  86. if (camp == null)
  87. {
  88. CheckErrors("未查询到正在运行的培训营!");
  89. return Content("Error");
  90. }
  91. }
  92. else
  93. {
  94. string campNo = id.IsEmpty() ? (string)Session["CampNo"] : id;
  95. if (campNo.IsEmpty())
  96. {
  97. TempData[ExerciseController.SelectDataKey] = new SelectCampModel
  98. {
  99. PageUrl = "/Play/IndexWithScore",
  100. PageTitle = "演示屏选择培训营",
  101. HasGroup = false
  102. };
  103. return RedirectToAction("SelectCamp", "Exercise");
  104. }
  105. camp = await CampRepository.FirstOrDefaultAsync(a => a.Id == campNo);
  106. if (camp == null)
  107. {
  108. CheckErrors($"未查到到编号为【{campNo}】的培训营!");
  109. return null;
  110. }
  111. Session["CampNo"] = campNo;
  112. Session.Timeout = TimeOut;
  113. }
  114. ViewBag.Camp = ObjectMapper.Map<CampDto>(camp);
  115. if (camp.CampState != CampStateDefinition.Run)
  116. {
  117. return View("Wait");
  118. }
  119. ViewBag.Groups = await QueryApp.GetCampGroups(id);
  120. return View();
  121. }
  122. }
  123. }