public async Task<ActionResult> GetUserContests() { var userId = User.Identity.GetUserId(); var currentContests = await this.Data.Contests.All() .Where(c => c.OwnerId == userId && c.State == TypeOfEnding.Ongoing) .OrderByDescending(c => c.ParticipationEndTime) .Select(OngoingContestBasicInfoViewModel.Create).ToListAsync(); var pastContests = await this.Data.Contests.All() .Where(c => c.OwnerId == userId && c.State != TypeOfEnding.Ongoing) .OrderByDescending(c => c.ContestEndTime) .Select(EndedContestBasicInfoViewModel.Create).ToListAsync(); var contests = new IndexPageViewModel() { EndedContests = pastContests, OngoingContests = currentContests }; ViewBag.msg = TempData["msg"]; return View("Contests", contests); }
public ActionResult Index() { var userId = User.Identity.GetUserId(); Expression<Func<Contest, bool>> wherePredicateCurrentContests; Expression<Func<Contest, bool>> wherePredicatePastContests; if (User.IsInRole("Admin")) { wherePredicateCurrentContests = c => c.State == TypeOfEnding.Ongoing; wherePredicatePastContests = c => c.State != TypeOfEnding.Ongoing; } else { wherePredicateCurrentContests = c => c.State == TypeOfEnding.Ongoing && ((c.ParticipationStrategy == Strategy.Open || c.VotingStrategy == Strategy.Open) || (c.Participants.Any(p => p.Id == userId) || c.CommitteeMembers.Any(p => p.Id == userId))); wherePredicatePastContests = c => c.State != TypeOfEnding.Ongoing && ((c.ParticipationStrategy == Strategy.Open || c.VotingStrategy == Strategy.Open) || (c.Participants.Any(p => p.Id == userId) || c.CommitteeMembers.Any(p => p.Id == userId))); } var ongoingContests = this.Data.Contests.All() .Where(wherePredicateCurrentContests) .OrderByDescending(c => c.ParticipationEndTime) .Select(OngoingContestBasicInfoViewModel.Create).ToList(); var endedContests = this.Data.Contests.All() .Where(wherePredicatePastContests) .OrderByDescending(c => c.ContestEndTime) .Select(EndedContestBasicInfoViewModel.Create).ToList(); var allContests = new IndexPageViewModel() { OngoingContests = ongoingContests, EndedContests = endedContests }; return View("Index", allContests); }