Exemple #1
0
        public void OpenVoting(Guid userGuid, string nickname)
        {
            lock (_users)
            {
                // can't open voting if it's not closed
                if (_votingState != VotingState.Closed)
                {
                    return;
                }

                _votingState = VotingState.Open;
                ActionEventQueue.Instance.Value.Add(new ResponseDTO {
                    UserGuid = userGuid, Nickname = nickname, Type = Types.VotingOpened
                });
            }
        }
Exemple #2
0
        public void CloseVoting(Guid userGuid, string nickname)
        {
            lock (_users)
            {
                // can't close voting if it's not open
                if (_votingState != VotingState.Open)
                {
                    return;
                }

                int yesCount     = _users.Values.Count(u => u.Vote == Vote.Yes);
                int noCount      = _users.Values.Count(u => u.Vote == Vote.No);
                int abstainCount = _users.Values.Count(u => u.Vote == Vote.Abstain || u.Vote == null);

                // TODO: include all results in message?
                string message;
                if (abstainCount > 0)
                {
                    message = $"vote results: {yesCount}/{noCount} (Abstain: {abstainCount})";
                }
                else
                {
                    message = $"vote results: {yesCount}/{noCount}";
                }

                _votingState = VotingState.Closed;
                ActionEventQueue.Instance.Value.Add(
                    new ResponseDTO
                {
                    UserGuid = userGuid, Nickname = nickname, Type = Types.VotingClosed, Message = message
                });

                foreach (var user in _users.Values)
                {
                    user.Vote = null;
                }
            }
        }