public ActionResult PuzzleMap(Guid puzzleId) { var puzzle = puzzleService.GetById(puzzleId); if (puzzle == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "找不到 puzzle")); } var teamId = new Guid(((ClaimsPrincipal)User).FindFirst("TeamId").Value ?? Guid.Empty.ToString()); var team = teamService.GetByIdIncludeAll(teamId); var teamRecord = team.TeamRecords; // 檢查是否已經有任何紀錄,若沒有則代表全新開始,寫入第一題記錄與開始時間 if (!teamRecord.Any()) { teamService.SetTeamStart(teamId); } // 檢查是否已經為目前最新進度,若非則跳轉 if (team.CurrentPuzzleId != puzzle.Id) { return(RedirectToAction("PuzzleMap", "Tour", new { puzzleId = team.CurrentPuzzleId })); } if (team.IsComplete) { return(RedirectToAction("Complete", "Tour", new { teamId })); } // 判斷是否已經通過地圖 var record = team.TeamRecords.OrderByDescending(x => x.Sort).First(x => x.TourPuzzle.PuzzleId == puzzle.Id); if (record.IsPassPuzzleMap) { return(RedirectToAction("Puzzle", "Tour", new { puzzleId = record.TourPuzzle.PuzzleId })); } // 設定到期時間 ViewBag.puzzleEndTime = record.PuzzleStartTime.AddMinutes(10); ViewBag.endTime = team.EndTime ?? DateTime.Now.AddHours(2); return(View(puzzle)); }
public ActionResult Edit(Guid puzzleId) { var data = puzzleService.GetById(puzzleId); if (data == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var tour = tourService.GetById(data.TourId); if (tour == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ViewBag.tour = tour; return(View(data)); }