Beispiel #1
0
        public int RegisterBet(string gamblerId, BetRequest betRequest)
        {
            try
            {
                BetEntity objBet;
                if (betValidation.ValidBetWithRouletteExist(betRequest.RouletteId))
                {
                    objBet = betModel.GetBets().Where(b => b.RouletteId == betRequest.RouletteId && b.Status == true).FirstOrDefault();
                }
                else
                {
                    int betId = 0;
                    List <BetEntity> objBets = betModel.GetBets();
                    if (objBets.Count > 0)
                    {
                        betId = objBets.Max(b => b.Id) + 1;
                    }
                    else
                    {
                        betId++;
                    }
                    objBet = betModel.CreateBet(betId, betRequest.RouletteId, status: true);
                }
                if (gamblingValidation.ValidGamblerAlreadyBetOnGambling(objBet.Id, gamblerId))
                {
                    return(0);
                }
                gamblingModel.InsertGambling(objBet, betRequest, gamblerId);
                gamblerModel.UpdateGamblerCredits(gamblerId, gamblerModel.GetOneGambler(gamblerId).Credits - betRequest.CreditsBet);

                return(objBet.Id);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public bool ValidBetWithRouletteExist(int RouletteId)
        {
            try
            {
                BetEntity objBet = betModel.GetBets().Where(b => b.RouletteId == RouletteId && b.Status == true).FirstOrDefault();
                if (objBet == null)
                {
                    return(false);
                }

                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }