public async Task <ActionResult> Details(int contestId) { if (!await HasAccess(contestId)) { return(RedirectToAction(nameof(Index)).WithWarning("此考试不存在或你无权限访问。")); } ContestDetailsModel details = await _manager.Get(contestId); ViewBag.IsOwner = await IsOwner(contestId); return(View(details)); }
public async Task <ContestDetailsModel> GetContestDetails(int cid) { var(user, privilege) = await GetUserPrivilegeAsync(); using (var db = new ApplicationDbContext(_dbContextOptions)) { var contest = await db.Contest.FindAsync(cid); var ret = new ContestDetailsModel { IsSucceeded = true }; if (contest == null || (contest.Hidden && !HasAdminPrivilege(privilege))) { ret.IsSucceeded = false; ret.ErrorMessage = "找不到该比赛"; } ret.Id = contest.Id; ret.Name = contest.Name; ret.UserId = contest.UserId; ret.UserName = (await _userManager.FindByIdAsync(contest.UserId))?.UserName; ret.RawStartTime = contest.StartTime; ret.RawEndTime = contest.EndTime; ret.Password = contest.Password; ret.Status = "进行中"; if (ret.RawEndTime < DateTime.Now) { ret.Status = "已结束"; } if (ret.RawStartTime > DateTime.Now) { ret.Status = "未开始"; } ret.Description = contest.Description; ret.ProblemCount = db.ContestProblemConfig.Count(j => j.ContestId == contest.Id); var config = JsonConvert.DeserializeObject <ContestConfiguration>(contest.Config ?? "{}"); ret.Type = config?.Type ?? ContestType.Generic; ret.SubmissionLimit = config?.SubmissionLimit ?? 0; return(ret); } }
public async Task <ActionResult> DetailsInQuestion(int contestId, int rank = 1) { if (!await HasAccess(contestId)) { return(RedirectToAction("Index").WithWarning("此考试不存在或你无权限访问。")); } if (!await _manager.IsContestStarted(contestId)) { return(RedirectToAction(nameof(Details), new { contestId }).WithWarning("考试未开始或已结束。")); } ContestDetailsModel details = await _manager.Get(contestId); ContestDetailsInQuestionModel vm = Mapper.Map <ContestDetailsInQuestionModel>(details); vm.CurrentQuestion = await _manager.GetQuestion(contestId, rank); vm.Rank = rank; return(View(vm)); }