public async Task <ActionResult> DisplayNominations(string year, string category) { if (!User.Identity.IsAuthenticated) { return(RedirectToAction("DisplayNominations", "Home", new YearCategoryModel(year, category))); } string userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); Moviegoer moviegoer = await MoviegoerAPI.GetByUserId(userId); List <Vote> myVotes = await VoteAPI.GetByIdentityUserIdYearOfNominationAndCategory(userId, year, category); bool hasVotedThisYear = myVotes.Where(v => v.Date.Year == DateTime.Now.Year).FirstOrDefault() != null; if (!hasVotedThisYear) { return(RedirectToAction(nameof(VoteOnNomination), new YearCategoryModel(year, category))); } NominationViewModel nominationViewModel = await CreateNominationViewModel(year, category); nominationViewModel.JsonVotes = JsonDataBuilder.CreateJsonVoteCollection(nominationViewModel); nominationViewModel.JsonNomineeNames = JsonDataBuilder.CreateJsonStringFromStringList(nominationViewModel.Nominations.Select(n => n.Nominee).ToList()); nominationViewModel.MyVotes = await VoteAPI.GetByIdentityUserIdYearOfNominationAndCategory(userId, year, category); nominationViewModel.AllYearCategoryCombinations = await NominationAPI.GetAllYearCategoryCombinations(); return(View(nominationViewModel)); }
public async Task <ActionResult> VoteOnNomination(string year, string category) { VoteViewModel voteViewModel = new VoteViewModel(); string userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); List <Vote> myVotes = await VoteAPI.GetByIdentityUserIdYearOfNominationAndCategory(userId, year, category); voteViewModel.Vote = myVotes.Where(v => v.Date.Year == DateTime.Now.Year).FirstOrDefault(); if (voteViewModel.Vote == null) { voteViewModel.Vote = await CreateNewVote(userId); } voteViewModel.Nominations = await NominationAPI.GetNominationsByYearAndCategoryIncludeMovie(year, category); return(View(voteViewModel)); }