using System.Threading.Tasks; using System.Web.Mvc; using System.Web.WebPages; using Abp.Web.Mvc.Authorization; using WeOnlineApp.BaseSystem.Query; using WeOnlineApp.Configuration; using WeOnlineApp.Models.Play; using WeOnlineApp.TrainingCampPlay; namespace WeOnlineApp.Controllers { [AbpMvcAuthorize] public class PlayController : IwbControllerBase { public PlayController(CampPlayAppService playApp, QueryAppService queryApp) { PlayApp = playApp; QueryApp = queryApp; } public CampPlayAppService PlayApp { get; } public QueryAppService QueryApp { get; } [AbpMvcAuthorize] public ActionResult Index() { CheckAccount(); return View(); } [AbpMvcAuthorize] public async Task Start() { CheckAccount(); var playNo = await PlayApp.GetRunPlay(); if (playNo.IsEmpty()) { return RedirectToAction("PlayList"); } return RedirectToAction("Ready", new { id = playNo }); } [AbpMvcAuthorize] public async Task Ready(string id) { CheckAccount(); if (id.IsEmpty()) { id = await PlayApp.GetRunPlay(); } if (id.IsEmpty()) { CheckErrors("未查询到您正在演练,请选择一个演练加入或自己创建一个演练再开始!"); } var play = await QueryApp.QueryPlay(id); if (play == null) { CheckErrors("未查询到演练,无法加入!"); return View(); } var playUser = await PlayApp.GetPlayUser(play.Id); if (play.PlayModel == CampPlayModelDefinition.Single) { if (playUser == null) { CheckErrors("单人演练,其他人无法加入!"); } } else if ((!await PlayApp.CheckIsRun(id)) && !play.IsPublic) { //CheckErrors("演练未公开,无法加入!"); return View("Code"); } CampPlayModel campPlay = new CampPlayModel() { Play = play, Camp = await QueryApp.QueryCamp(play.CampNo), PlayUser = playUser }; ViewBag.CampPlay = campPlay; if (play.PlayState == CampPlayStateDefinition.New) { return View("_Run/Ready", campPlay); } return View("_Run/Run", campPlay); //return View("Run", campPlay); } [AllowAnonymous] [AccessOriginal] public async Task Display(string id) { var play = await QueryApp.QueryPlay(id); var playUser = await PlayApp.GetPlayUser(play.Id); CampPlayModel campPlay = new CampPlayModel() { Play = play, Camp = await QueryApp.QueryCamp(play.CampNo), PlayUser = playUser }; ViewBag.CampPlay = campPlay; return View("_Run/Display", campPlay); } public ActionResult Code() { return View(); } public async Task Run(string id) { if (id.IsEmpty()) { CheckErrors("未查询演练,请重新选择一个演练加入或自己创建一个演练再开始!"); } var play = await PlayApp.GetPlayByCode(id); if (play == null) { CheckErrors("未查询到演练,无法加入!"); return View("Index"); } CampPlayModel campPlay = new CampPlayModel() { Play = play, Camp = await QueryApp.QueryCamp(play.CampNo), PlayUser = await PlayApp.GetPlayUser(play.Id) }; ViewBag.CampPlay = campPlay; if (play.PlayState == CampPlayStateDefinition.New) { return View("_Run/Ready", campPlay); } return View("_Run/Run", campPlay); //return View(); } [AbpMvcAuthorize] public ActionResult PlayList() { CheckAccount(); return View(); } [AbpMvcAuthorize] public async Task Create(string id) { CheckAccount(); if (id.IsEmpty()) { CheckErrors("课程编号不能为空!"); } ViewBag.PageId = "start"; ViewBag.Camp = await QueryApp.QueryCamp(id); return View(); } [AbpMvcAuthorize] public async Task Detail(string id) { CheckAccount(); if (id.IsEmpty()) { CheckErrors("课程编号不能为空!"); } ViewBag.PageId = "start"; ViewBag.Camp = await QueryApp.QueryCamp(id); return View(); } [AbpMvcAuthorize] public async Task DetailByPlay(string id) { CheckAccount(); if (id.IsEmpty()) { CheckErrors("课程编号不能为空!"); } ViewBag.PageId = "start"; ViewBag.Camp = await QueryApp.QueryCampByPlay(id); return View("Detail"); } public async Task Study(string id) { CheckAccount(); ViewBag.Camp = await QueryApp.QueryCampWithStudy(id); return View(); } public ActionResult History() { CheckAccount(); return View(); } public ActionResult Medal() { CheckAccount(); return View(); } public ActionResult Team() { CheckAccount(); return View(); } public async Task Report(string id) { CheckAccount(); if (id.IsEmpty()) { CheckErrors("演练编号不能为空!"); } var play = await PlayApp.GetReportPlay(id); if (play == null) { CheckErrors("未查询到演练!"); } ViewBag.Play = play; return View(); } } }