public static string ToHumanReadable(this CommentRestrictionEnum restriction)
        {
            switch (restriction)
            {
            case CommentRestrictionEnum.CitizenCanComment:
                return("citizens and congressmen can comment");

            case CommentRestrictionEnum.CitizenCanView:
                return("congressmen can comment and citizens are able to view comments");

            case CommentRestrictionEnum.OnlyCongressmen:
                return("only congressmen can view and comment");
            }
            throw new NotImplementedException();
        }
예제 #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
        }