public void ProcessCommand(Command newCommand) { bool voteActive = _currentVote != null && _currentVote.IsActive; if (newCommand.Args.Length > 0) { string voteType = newCommand.Args[0].ToLower(); if (newCommand.Sender.IsAdmin) { if (voteType == "enable" && !_enabled) { _enabled = true; Chat.SendMessage("Voting enabled."); return; } else if (voteType == "disable" && _enabled) { _enabled = false; Chat.SendMessage("Voting disabled."); return; } } Action votePassed; if (_enabled && !voteActive && VoteTypes.TryGetValue(voteType, out votePassed)) { _currentVote = new Vote(voteType, 0.75f, votePassed); Chat.SendMessage("VOTE STARTED BY " + newCommand.Sender.Name + ": " + voteType); Chat.SendMessage("Type /vote for yes"); _currentVote.AddVote(newCommand.Sender); } } else if (_enabled && voteActive && !_currentVote.Votes.Contains(newCommand.Sender.Slot)) { _currentVote.AddVote(newCommand.Sender); } if (!_enabled) { Chat.SendMessage("Voting is disabled."); } }
public void Add_Vote_With_Invalid_Comment_Shoud_Raise_Error() { //Arrange var employeeId = Guid.NewGuid(); var tasksId = Guid.NewGuid(); var comment = string.Empty; var vote = new Vote(); //Act var result = vote.AddVote(employeeId, tasksId, comment, _notificationHandler); //Assert Assert.True(_notificationHandler.HasNotification()); Assert.Contains(_notificationHandler.GetAll(), e => e.DetailedMessage == Vote.EntityError.InvalidComment.ToString()); Assert.DoesNotContain(_notificationHandler.GetAll(), e => e.DetailedMessage == Vote.EntityError.InvalidEmployeeId.ToString()); Assert.DoesNotContain(_notificationHandler.GetAll(), e => e.DetailedMessage == Vote.EntityError.InvalidTaskId.ToString()); }
public void PlayerVoteFor(Player player, Vote.Options option) { currentVote.AddVote(player, option); RpcPlayerVoteFor(player.gameObject, (byte)option); if (currentVote.Ended) { var result = currentVote.GetResult(); if (result == Vote.Options.Yes) { RpcVotePassed(); } else if (result == Vote.Options.No) { RpcVoteFailed(); } TargetOnVoteResult(currentVote.Owner.connectionToClient, (byte)currentVote.GetResult()); currentVote = null; } }
public async Task <AddVoteResponse> Handle(AddVoteCommand command, CancellationToken cancellationToken) { if (!IsValid(command)) { return(null); } var employee = await _employeeRepository.GetEmployeeById(command.EmployeeId); if (employee == null) { InvalidEmployee(_notification); } if (_notification.HasNotification()) { return(null); } var tasks = await _taskRepository.GetTasksById(command.TaskId); if (tasks == null) { InvalidTask(_notification); } if (_notification.HasNotification()) { return(null); } var alreadyVoted = await _voteRepository.ValidateVoteByEmployeeId(command.EmployeeId); if (alreadyVoted) { EmployeeAlreadyVoted(_notification); } if (_notification.HasNotification()) { return(null); } var vote = new Vote(); vote = vote.AddVote(command.EmployeeId, command.TaskId, command.Comment, _notification); if (_notification.HasNotification()) { return(null); } using (var uow = _unitOfWorkManager.Begin()) { await _voteRepository.AddVote(vote); uow.Complete(); } return(VoteResponse(vote)); }