public ContestEditModel() { Competitors = new List <Competitor>(); Config = new ContestConfiguration(); }
public async Task <List <StatusListItemModel> > GetStatusList(int start = 0, int count = 10, int pid = 0, int cid = 0, int gid = 0, bool onlyMe = false) { var(user, privilege) = await GetUserPrivilegeAsync(); using (var db = new ApplicationDbContext(_dbContextOptions)) { IQueryable <Judge> list; string contestName = null, groupName = null; ContestConfiguration config = null; if (cid == 0 && gid == 0) { list = db.Judge.OrderByDescending(i => i.Id).Where(i => i.ContestId == null && i.GroupId == null); } else { var contest = await db.Contest.Select(i => new { i.Id, i.Config, i.EndTime, i.Name }).FirstOrDefaultAsync(i => i.Id == cid); if (contest != null) { contestName = contest.Name; config = JsonConvert.DeserializeObject <ContestConfiguration>(contest.Config ?? "{}"); if (!HasAdminPrivilege(privilege)) { if (config != null) { if (config.ResultMode == ResultDisplayMode.Never || (config.ResultMode == ResultDisplayMode.AfterContest && contest.EndTime > DateTime.Now)) { return(new List <StatusListItemModel>()); } } } } if (gid != 0) { var group = await db.Group.Select(i => new { i.Id, i.Name }).FirstOrDefaultAsync(i => i.Id == gid); if (group != null) { groupName = group.Name; } list = db.Judge.OrderByDescending(i => i.Id).Where(i => i.ContestId == cid && i.GroupId == gid); } else { list = db.Judge.OrderByDescending(i => i.Id).Where(i => i.ContestId == cid && i.GroupId == null); } if (config?.AutoStopRank ?? false) { list = list.Where(i => i.JudgeTime.AddHours(1) < contest.EndTime); } } if (pid != 0) { list = list.Where(i => i.ProblemId == pid); } if (user != null && onlyMe) { list = list.Where(i => i.UserId == user.Id); } var result = await list.Include(i => i.Problem).Include(i => i.UserInfo).Include(i => i.Contest).Include(i => i.Group).Skip(start).Take(count).Select(i => new StatusListItemModel { Id = i.Id, GroupId = i.GroupId ?? 0, ContestId = i.ContestId ?? 0, FullScore = i.FullScore, Language = i.Language, ProblemId = i.ProblemId, RawJudgeTime = i.JudgeTime, ResultType = i.ResultType, UserId = i.UserId, RawType = i.Type, GroupName = i.Group.Name, ContestName = i.Contest.Name, ProblemName = i.Problem.Name, UserName = i.UserInfo.UserName }).ToListAsync(); foreach (var i in result) { if (config != null && config.ScoreMode == ScoreCountingMode.OnlyAccepted) { if (i.ResultType != (int)ResultCode.Accepted) { i.FullScore = 0; } } } return(result); } }