Exemplo n.º 1
0
 public ActionResult GetPlayerById(long playerId)
 {
     try
     {
         return(Ok(_playerServices.GetPlayerById(playerId)));
     }
     catch (Exception ex)
     {
         return(StatusCode(StatusCodes.Status400BadRequest, new ErrorAnswerDTO()
         {
             State = StatusCodes.Status400BadRequest,
             Mistakes = new List <ErrorDTO>(new[]
             {
                 new ErrorDTO()
                 {
                     Code = "",
                     Description = ex.Message
                 }
             })
         }));
     }
 }
Exemplo n.º 2
0
        public TransactionDTO <string> CreateBet(CreateBetDTO createBet)
        {
            TransactionDTO <string> transaction = new TransactionDTO <string>();

            try
            {
                var getPlayerById = _playerServices.GetPlayerById(createBet.PlayerId);
                if (getPlayerById.Data == null || getPlayerById.Data.Id == 0)
                {
                    transaction.Status  = Common.Status.Failure;
                    transaction.Message = getPlayerById.Message;
                    return(transaction);
                }
                ValidateBalancePlayerId validateBalancePlayerId = new ValidateBalancePlayerId(createBet.PlayerId, createBet.Prize);
                var validatePlayerBalance = _playerServices.ValidatePlayerBalance(validateBalancePlayerId);
                if (!validatePlayerBalance.Data)
                {
                    transaction.Status  = Common.Status.Failure;
                    transaction.Message = validatePlayerBalance.Message;
                    return(transaction);
                }
                var validateBet = ValidateBet(createBet);
                if (!validateBet.Data)
                {
                    transaction.Status  = Common.Status.Failure;
                    transaction.Message = validateBet.Message;
                    return(transaction);
                }
                var validateRouletteStatus = _rouletteServices.ValidateRouletteStatus(createBet.RouletteId);
                if (!validateRouletteStatus.Data)
                {
                    transaction.Status  = Common.Status.Failure;
                    transaction.Message = validateRouletteStatus.Message;
                    return(transaction);
                }
                if (createBet.Prize > 10000)
                {
                    transaction.Status  = Common.Status.Failure;
                    transaction.Message = "La apuesta supera el valor permitido de 10000.";
                    return(transaction);
                }
                var getBetTypeByCode = _betTypeServices.GetBetTypeByCode(createBet.BetType);
                if (getBetTypeByCode.Data.Id == 0)
                {
                    transaction.Status  = Common.Status.Failure;
                    transaction.Message = getBetTypeByCode.Message;
                    return(transaction);
                }
                createBet.BetTypeId = getBetTypeByCode.Data.Id;
                var transCreateBet = _betServices.CreateBet(createBet);
                transaction.Status  = (transCreateBet.Data.Flag) ? Common.Status.Success : Common.Status.Failure;
                transaction.Message = transCreateBet.Message;
                transaction.Data    = transCreateBet.Data.Message;
            }
            catch (ArgumentException ex)
            {
                transaction.Status  = Common.Status.Failure;
                transaction.Message = ex.Message;
            }

            return(transaction);
        }