static public ViewVotingBaseViewModel Instantiate(Entities.CongressVoting voting, ICongressVotingService congressVotingService) { bool isPlayerCongressman = false; bool canVote = false; var currentEntity = SessionHelper.CurrentEntity; if (currentEntity.Citizen != null) { var citizen = currentEntity.Citizen; if (citizen?.Congressmen.Any(c => c.CountryID == voting.CountryID) == true) { isPlayerCongressman = true; } canVote = congressVotingService.CanVote(citizen, voting); } return(instantiate(voting.GetVotingType(), voting, isPlayerCongressman, canVote)); }
private ActionResult Vote(int congressVotingID, VoteTypeEnum voteType) { var voting = congressVotingRepository.GetById(congressVotingID); var entity = SessionHelper.CurrentEntity; if (entity.Citizen == null) { AddError("Wrong entity"); return(RedirectToAction("ViewVoting", new { votingID = congressVotingID })); } var citizen = entity.Citizen; if (voting.CommentRestrictionID != (int)CommentRestrictionEnum.CitizenCanComment && voting.Country.Congressmen.Any(c => c.CitizenID == citizen.ID) == false) { AddError("You cannot vote on this!"); return(RedirectToAction("ViewVoting", new { votingID = congressVotingID })); } if (congressVotingService.CanVote(citizen, voting) == false) { AddError("You cannot vote!"); return(RedirectToAction("ViewVoting", new { votingID = congressVotingID })); } if (voting.GetTimeLeft(GameHelper.CurrentDay).TotalSeconds <= 0) { AddError("You cannot vote!"); return(RedirectToAction("ViewVoting", new { votingID = congressVotingID })); } congressVotingService.AddVote(voting, citizen, voteType); AddInfo("You had voted"); return(RedirectToAction("ViewVoting", new { votingID = congressVotingID })); }