public IActionResult Post([FromBody] BetSlipInfo betSlipInfo)
        {
            try
            {
                if (betSlipInfo != null)
                {
                    _logger.LogInformation("API Request hit: INSERT BetSlip with Bets : ");
                    var result = _betRepository.Add(betSlipInfo);

                    if (result == betSlipInfo.Bets.Count() + 1)
                    {
                        return(Ok("{\"status\": \"Success\"}"));
                    }
                    else
                    {
                        _logger.LogInformation("API Request (INSERT BetSlip with Bets : ) not committed");
                        return(NotFound("Failed: INSERT could not commit"));
                    }
                }
                else
                {
                    _logger.LogInformation("API Request hit (INSERT BetSlip with Bets) with null entry");
                    return(BadRequest("Failed: null entry"));
                }
            }

            catch (Exception e)
            {
                _logger.LogError("API Request (INSERT BetSlip with Bets) FAILED: ", e);
                return(BadRequest(e));
            }
        }
Beispiel #2
0
        public void AddBet(Bet bet, Bettor bettor, Brother betTarget, string[] predictedOutcomes)
        {
            if (bet == null)
            {
                throw new ArgumentNullException(nameof(bet));
            }
            if (bet.Id != default(int))
            {
                throw new ArgumentException(nameof(bet));
            }
            if (bettor == null)
            {
                throw new ArgumentNullException(nameof(bettor));
            }
            if (bettor.Id == default(int))
            {
                throw new ArgumentException(nameof(bettor));
            }
            if (betTarget == null)
            {
                throw new ArgumentNullException(nameof(betTarget));
            }
            if (betTarget.Id == default(int))
            {
                throw new ArgumentException(nameof(betTarget));
            }
            if (predictedOutcomes == null)
            {
                throw new ArgumentNullException(nameof(predictedOutcomes));
            }

            if (bet.Expiration < DateTime.Today.AddDays(2))
            {
                throw new Exception(
                          $"Come on, you need to give more time than that! Set the date to at least {DateTime.Today.AddDays(2).ToShortDateString()}");
            }

            var betOutcomes = predictedOutcomes
                              .Where(o => !string.IsNullOrWhiteSpace(o))
                              .Select(o => new BetOption()
            {
                Outcome = o, Bet = bet
            });

            bet.BetOptions = new List <BetOption>(betOutcomes);
            if (bet.BetOptions.Count < 2)
            {
                throw new Exception("Bets must have at least two outcomes");
            }
            _betRepository.Add(bet, bettor, betTarget);
        }