Пример #1
0
        public void ValidateUpdateBet(Bet bet)
        {
            var betToUpdate = betsRepository.GetBet(bet.BetId);

            if (betToUpdate == null)
            {
                AddLog(ActionType.ERROR, string.Format("Bet {0} dosen't exist", bet.BetId));
                throw new ArgumentException(string.Format("Bet {0} dosen't exist", bet.BetId));
            }
            if (String.IsNullOrEmpty(bet.UserId))
            {
                AddLog(ActionType.ERROR, string.Format("Updated bet {0} must have user", bet.BetId));
                throw new ArgumentException(string.Format("Updated bet {0} must have user", bet.BetId));
            }
            if (betToUpdate.UserId != bet.UserId)
            {
                AddLog(ActionType.UNAUTHORIZED_ACCESS, "You can't update a bet that is not yours");
                throw new UnauthorizedAccessException("You can't update a bet that is not yours");
            }
            var game = gamesRepository.GetGame(betToUpdate.GameId);

            if (!game.IsOpen(dateTimeProvider.UTCNow))
            {
                AddLog(ActionType.ERROR, string.Format("Game {0} is closed for betting", game.GameId));
                throw new ArgumentException(string.Format("Game {0} is closed for betting", game.GameId));
            }
        }
Пример #2
0
        public BetViewModel GetBetById(int id)
        {
            var item = betsRepository.GetBet(id);

            if (item == null)
            {
                throw new ObjectNotFoundException(string.Format("Bet with id '{0}' not found", id));
            }

            return(new BetViewModel(item, dateTimeProvider.UTCNow));
        }