Exemplo n.º 1
0
        public void ChangePrice(GameVote vote)
        {
            var Votes    = _gameVoteRepository.GetVotes(vote.GameId);
            int decrease = 0;
            int increase = 0;

            foreach (GameVote i in Votes)
            {
                if (i.Vote_type == 1)
                {
                    decrease++;
                }
                if (i.Vote_type == 3)
                {
                    increase++;
                }
            }
            if (decrease > increase)
            {
                if ((decrease - increase) > 50)
                {
                    _advertisementRepository.ChangePriceAfterGame(false, vote.Game.CardId, 50);
                }
                else
                {
                    _advertisementRepository.ChangePriceAfterGame(false, vote.Game.CardId, decrease - increase);
                }
            }
            if (decrease < increase)
            {
                if ((increase - decrease) > 50)
                {
                    _advertisementRepository.ChangePriceAfterGame(true, vote.Game.CardId, 50);
                }
                else
                {
                    _advertisementRepository.ChangePriceAfterGame(true, vote.Game.CardId, increase - decrease);
                }
            }
            _gameVoteRepository.DeleteVotes(vote.GameId);
            _gameRepository.Delete(vote.GameId);
            _advertisementRepository.RemoveFromGame(vote.Game.CardId);
        }
Exemplo n.º 2
0
        public ViewResult Vote(int value, int id)
        {
            Game     game      = _gameRepository.GetGame(id);
            string   accountId = HttpContext.Session.GetString("username");
            Account  acc       = _accountRepository.GetUserByEmail(accountId);
            GameVote vote      = new GameVote {
                Game = game, User = acc, Vote_type = value
            };

            _gameVoteRepository.SaveVote(vote);
            _gameRepository.Update(game.Id);
            if (game.GameVote == game.MaxVoteCount)
            {
                ChangePrice(vote);
            }
            Game result = _gameRepository.GetGameByUserId(accountId);

            return(View("GameScreen", result));
        }