Пример #1
0
        public void CastBallot(Motion motion, Choice choice)
        {
            var b = new Ballot();

            b.Choice    = choice;
            b.Motion    = motion;
            b.Moderator = this;
            motion.Votes.Add(b);
            b.Insert();
        }
Пример #2
0
        private void CommandCast(ChatCommand cmd, Moderator mod)
        {
            var usage = "usage: $vote cast [choice]{ yes | no | abstain } [motion id] ";

            if (cmd.Args.Length == 0)
            {
                WriteUser(usage, mod, cmd.Source);
                return;
            }

            var stuff = cmd.Args.Split(' ');

            if (stuff.GetUpperBound(0) < 1)
            {
                WriteUser(usage, mod, cmd.Source);
                return;
            }

            var id = -1;

            try
            {
                id = Int32.Parse(stuff[1]);
            }
            catch
            {
                WriteUser(usage, mod, cmd.Source);
                return;
            }

            Choice c     = Choice.Abstain;
            bool   error = false;

            switch (stuff[0].ToLower())
            {
            case "yes":
            case "y":
            case "+1":
            case "yay":
            case "yae":
            case "yea":
            case "oui":
            case "si":
            case "ja":
            case "da":
                c = Choice.Yes;
                break;

            case "no":
            case "n":
            case "-1":
            case "nae":
            case "nay":
            case "non":
            case "nein":
            case "neit":
                c = Choice.No;
                break;

            case "abstain":
            case "abs":
            case "0":
                c = Choice.Abstain;
                break;

            default:
                error = true;
                break;
            }

            if (error)
            {
                WriteUser(usage, mod);
                return;
            }

            WriteUser("Submitting ballot.  Please wait.", mod, cmd.Source);

            var motion = Motion.GetMotion(id);
            var b      = new Ballot();

            b.Choice    = c;
            b.Moderator = mod;
            b.Motion    = motion;
            b.Insert();

            WriteUser("Your ballot has been recorded", mod, cmd.Source);
        }