Ejemplo n.º 1
0
        public PartialViewResult DisplayVotingInfo(VotingTypeEnum votingType, int votingID)
        {
            var voting = congressVotingRepository.GetById(votingID);
            CongressVotingViewModel vm = CongressVotingViewModelChooser.GetViewModel(votingType, voting);

            return(PartialView(vm));
        }
Ejemplo n.º 2
0
        public ActionResult StartVoting(int countryID, FormCollection values)
        {
            try
            {
                var entity = SessionHelper.CurrentEntity;

                if (entity.Is(EntityTypeEnum.Citizen) == false)
                {
                    return(RedirectBackWithError("You are not a citizen."));
                }

                var citizen = entity.Citizen;
                var country = countryRepository.GetById(countryID);

                if (country == null)
                {
                    return(RedirectBackWithError("Country does not exist!"));
                }

                if (congressVotingService.IsCongressman(citizen, country) == false)
                {
                    return(RedirectBackWithError("You are not a party member of this country!"));
                }

                if (citizen.Congressmen.First(c => c.CountryID == countryID).LastVotingDay >= GameHelper.CurrentDay)
                {
                    AddError("You started voting today!");
                    return(RedirectToAction("Votings", new { countryID = countryID }));
                }

                if (country.Congressmen.Count < 3)
                {
                    AddWarning("You cannot vote when there is less than 3 congressmen. [Feature will be enabled in release version. You can vote without problems]");
                }

                var votingTypes         = congressVotingRepository.GetVotingTypes();
                var commentRestrictions = congressVotingRepository.GetCommentRestrictions();


                var vm = new CongressStartVotingViewModel(votingTypes, commentRestrictions, country);

                var votingType = (VotingTypeEnum)int.Parse(values["VotingType"]);

                var vote = CongressVotingViewModelChooser.GetViewModel(votingType, values);



                if (TryValidateModel(vote, "EmbeddedVote"))
                {
                    CommentRestrictionEnum commentRestriction = (CommentRestrictionEnum)int.Parse(values["CommentRestriction"]);
                    var parameters = vote.CreateVotingParameters();

                    parameters.CommentRestriction = commentRestriction;
                    parameters.Country            = country;
                    parameters.Creator            = citizen;
                    parameters.CreatorMessage     = vote.Message;
                    parameters.VotingLength       = country.CountryPolicy.CongressVotingLength;

                    var voting = congressVotingService.StartVote(parameters);

                    return(RedirectToAction("ViewVoting", new { votingID = voting.ID }));
                }
                vm.EmbedPostVote(vote);
                return(View(vm));
            }
#if !DEBUG
            catch (Exception e)
            {
                if (e is UserReadableException)
                {
                    AddError(e.Message);
                }
                Elmah.ErrorSignal.FromCurrentContext().Raise(e);
                return(RedirectBack());
            }
#else
            catch (UserReadableException e)
            {
                AddError(e.Message);
                return(RedirectBack());
            }
#endif
        }
Ejemplo n.º 3
0
        public PartialViewResult EditOptionForm(VotingTypeEnum votingType, int countryID)
        {
            CongressVotingViewModel vm = CongressVotingViewModelChooser.GetViewModel(votingType, countryID);

            return(PartialView(vm));
        }