示例#1
0
        //admin get bets by search paramaters model
        public IEnumerable <BetListItem> AdminGetBets(GetBetByParameters model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                //F F F
                if (model is null) //this will return ALL bets EVER
                {
                    var query =
                        ctx
                        .Bets
                        .Where(e => e.GameId > 0)
                        .Select(
                            e =>
                            new BetListItem
                    {
                        BetId         = e.BetId,
                        PlayerId      = e.PlayerId,
                        TimeOfBet     = e.DateTimeOfBet.ToString(),
                        GameId        = e.GameId,
                        BetAmount     = e.BetAmount,
                        PlayerWonGame = e.PlayerWonGame,
                        PayoutAmount  = e.PayoutAmount
                    }
                            );
                    return(query.ToArray());
                }
                //All 3 parameters
                //T T T
                if (model.PlayerWonGame.HasValue && model.Time.HasValue && model.BetAmount.HasValue)
                {
                    int            noOfDays = (int)model.Time;
                    DateTimeOffset date     = DateTimeOffset.Now.Subtract(new TimeSpan(noOfDays, 0, 0, 0));
                    var            query    =
                        ctx
                        .Bets
                        .Where(e => e.PlayerWonGame == model.PlayerWonGame && e.DateTimeOfBet > date && e.BetAmount >= model.BetAmount)
                        .Select(
                            e =>
                            new BetListItem
                    {
                        BetId         = e.BetId,
                        PlayerId      = e.PlayerId,
                        TimeOfBet     = e.DateTimeOfBet.ToString(),
                        GameId        = e.GameId,
                        BetAmount     = e.BetAmount,
                        PlayerWonGame = e.PlayerWonGame,
                        PayoutAmount  = e.PayoutAmount
                    }
                            );

                    return(query.ToArray());
                }
                //T T F

                if (model.PlayerWonGame.HasValue && model.Time.HasValue && !model.BetAmount.HasValue)
                {
                    int            noOfDays = (int)model.Time;
                    DateTimeOffset date     = DateTimeOffset.Now.Subtract(new TimeSpan(noOfDays, 0, 0, 0));
                    var            query    =
                        ctx
                        .Bets
                        .Where(e => e.PlayerWonGame == model.PlayerWonGame && e.DateTimeOfBet > date)
                        .Select(
                            e =>
                            new BetListItem
                    {
                        BetId         = e.BetId,
                        PlayerId      = e.PlayerId,
                        TimeOfBet     = e.DateTimeOfBet.ToString(),
                        GameId        = e.GameId,
                        BetAmount     = e.BetAmount,
                        PlayerWonGame = e.PlayerWonGame,
                        PayoutAmount  = e.PayoutAmount
                    }
                            );

                    return(query.ToArray());
                }
                //T F T
                if (model.PlayerWonGame.HasValue && !model.Time.HasValue && model.BetAmount.HasValue)
                {
                    var query =
                        ctx
                        .Bets
                        .Where(e => e.PlayerWonGame == model.PlayerWonGame && e.BetAmount >= model.BetAmount)
                        .Select(
                            e =>
                            new BetListItem
                    {
                        BetId         = e.BetId,
                        PlayerId      = e.PlayerId,
                        TimeOfBet     = e.DateTimeOfBet.ToString(),
                        GameId        = e.GameId,
                        BetAmount     = e.BetAmount,
                        PlayerWonGame = e.PlayerWonGame,
                        PayoutAmount  = e.PayoutAmount
                    }
                            );

                    return(query.ToArray());
                }
                //T F F
                if (model.PlayerWonGame.HasValue && !model.Time.HasValue && !model.BetAmount.HasValue)
                {
                    var query =
                        ctx
                        .Bets
                        .Where(e => e.PlayerWonGame == model.PlayerWonGame)
                        .Select(
                            e =>
                            new BetListItem
                    {
                        BetId         = e.BetId,
                        PlayerId      = e.PlayerId,
                        TimeOfBet     = e.DateTimeOfBet.ToString(),
                        GameId        = e.GameId,
                        BetAmount     = e.BetAmount,
                        PlayerWonGame = e.PlayerWonGame,
                        PayoutAmount  = e.PayoutAmount
                    }
                            );

                    return(query.ToArray());
                }
                //F T T
                if (!model.PlayerWonGame.HasValue && model.Time.HasValue && model.BetAmount.HasValue)
                {
                    int            noOfDays = (int)model.Time;
                    DateTimeOffset date     = DateTimeOffset.Now.Subtract(new TimeSpan(noOfDays, 0, 0, 0));
                    var            query    =
                        ctx
                        .Bets
                        .Where(e => e.DateTimeOfBet > date && e.BetAmount >= model.BetAmount)
                        .Select(
                            e =>
                            new BetListItem
                    {
                        BetId         = e.BetId,
                        PlayerId      = e.PlayerId,
                        TimeOfBet     = e.DateTimeOfBet.ToString(),
                        GameId        = e.GameId,
                        BetAmount     = e.BetAmount,
                        PlayerWonGame = e.PlayerWonGame,
                        PayoutAmount  = e.PayoutAmount
                    }
                            );

                    return(query.ToArray());
                }
                //F F T
                if (!model.PlayerWonGame.HasValue && !model.Time.HasValue && model.BetAmount.HasValue)
                {
                    var query =
                        ctx
                        .Bets
                        .Where(e => e.BetAmount >= model.BetAmount)
                        .Select(
                            e =>
                            new BetListItem
                    {
                        BetId         = e.BetId,
                        PlayerId      = e.PlayerId,
                        TimeOfBet     = e.DateTimeOfBet.ToString(),
                        GameId        = e.GameId,
                        BetAmount     = e.BetAmount,
                        PlayerWonGame = e.PlayerWonGame,
                        PayoutAmount  = e.PayoutAmount
                    }
                            );

                    return(query.ToArray());
                }
                // F T F
                if (!model.PlayerWonGame.HasValue && model.Time.HasValue && !model.BetAmount.HasValue)
                {
                    int            noOfDays = (int)model.Time;
                    DateTimeOffset date     = DateTimeOffset.Now.Subtract(new TimeSpan(noOfDays, 0, 0, 0));
                    var            query    =
                        ctx
                        .Bets
                        .Where(e => e.DateTimeOfBet > date)
                        .Select(
                            e =>
                            new BetListItem
                    {
                        BetId         = e.BetId,
                        PlayerId      = e.PlayerId,
                        TimeOfBet     = e.DateTimeOfBet.ToString(),
                        GameId        = e.GameId,
                        BetAmount     = e.BetAmount,
                        PlayerWonGame = e.PlayerWonGame,
                        PayoutAmount  = e.PayoutAmount
                    }
                            );

                    return(query.ToArray());
                }

                return(null);
            }
        }
示例#2
0
        public IHttpActionResult PostbyAdminSearch([FromBody] GetBetByParameters model)
        {
            var bets = _service.AdminGetBets(model);

            return(Ok(bets));
        }