public TransactionDTO <MessageDTO> CreateBet(CreateBetDTO createBet) { TransactionDTO <MessageDTO> transaction = new TransactionDTO <MessageDTO>(); transaction.Data = new MessageDTO(); try { long createRouletteId = _betRepository.CreateBet(createBet); if (createRouletteId < 0) { transaction.Status = Common.Status.Failure; transaction.Message = "No fue posible crear la apuesta de juego."; return(transaction); } transaction.Data.Message = "¡Apuesta aceptada! :)"; transaction.Data.Flag = true; } catch (ArgumentException ex) { transaction.Status = Common.Status.Failure; transaction.Message = ex.Message; } return(transaction); }
private TransactionDTO <bool> ValidateBet(CreateBetDTO createBet) { ValidateBetDTO validateBet = new ValidateBetDTO(); validateBet.RouletteId = createBet.RouletteId; validateBet.Bet = createBet.Bet; TransactionDTO <bool> transaction = new TransactionDTO <bool>(); switch (createBet.BetType) { case CodeBet.Color: transaction = _rouletteConfigurationServices.ValidateColorByRouletteId(validateBet); break; case CodeBet.Number: transaction = _rouletteConfigurationServices.ValidateNumberByRouletteId(validateBet); break; default: transaction.Message = "El tipo de apuesta escogido no es valido."; transaction.Status = Common.Status.Failure; transaction.Data = false; break; } return(transaction); }
/// <summary> /// Method for creating the bet /// </summary> /// <param name="createBet"> Object for the creation of the bet </param> /// <returns> Creation flag </returns> public long CreateBet(CreateBetDTO createBet) { long id = 0; using (SqlConnection connection = new SqlConnection(ConnectionString)) { using (SqlCommand sqlCommand = new SqlCommand("develop.CreateBet", connection)) { sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.Parameters.Add(new SqlParameter("@PlayerId", SqlDbType.BigInt)); sqlCommand.Parameters["@PlayerId"].Value = createBet.PlayerId; sqlCommand.Parameters.Add(new SqlParameter("@BetTypeId", SqlDbType.BigInt)); sqlCommand.Parameters["@BetTypeId"].Value = createBet.BetTypeId; sqlCommand.Parameters.Add(new SqlParameter("@RouletteId", SqlDbType.BigInt)); sqlCommand.Parameters["@RouletteId"].Value = createBet.RouletteId; sqlCommand.Parameters.Add(new SqlParameter("@Bet", SqlDbType.NVarChar, 10)); sqlCommand.Parameters["@Bet"].Value = createBet.Bet; sqlCommand.Parameters.Add(new SqlParameter("@Prize", SqlDbType.Float)); sqlCommand.Parameters["@Prize"].Value = createBet.Prize; sqlCommand.Parameters.Add(new SqlParameter("@Id", SqlDbType.BigInt)); sqlCommand.Parameters["@Id"].Direction = ParameterDirection.Output; try { connection.Open(); sqlCommand.ExecuteNonQuery(); id = (long)sqlCommand.Parameters["@Id"].Value; } catch (Exception ex) { throw new ArgumentException("Error 13: Ocurrió un error consultando la base de datos."); } finally { connection.Close(); } return(id); } } }
public ActionResult CreateBet(CreateBetDTO createBet) { try { return(Ok(_betTransactions.CreateBet(createBet))); } catch (Exception ex) { return(StatusCode(StatusCodes.Status400BadRequest, new ErrorAnswerDTO() { State = StatusCodes.Status400BadRequest, Mistakes = new List <ErrorDTO>(new[] { new ErrorDTO() { Code = "", Description = ex.Message } }) })); } }
public TransactionDTO <MessageDTO> CreateBet(CreateBetDTO createBet) { return(_betBl.CreateBet(createBet)); }
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); }