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)); }
private async Task <NominationViewModel> CreateNominationViewModel(string year, string category) { NominationViewModel nominationViewModel; try { int yearInt = int.Parse(year); nominationViewModel = new NominationViewModel() { Nominations = await NominationAPI.GetNominationsByYearAndCategoryIncludeMovie(year, category), Votes = await VoteAPI.GetVotesByYearOfNominationAndCategory(year, category), Year = yearInt, Category = category }; } catch { nominationViewModel = null; } return(nominationViewModel); }