Пример #1
0
        public bool ValidCloseBetData(int rouletteId, CloseBetRequest closeBetRequest)
        {
            try
            {
                if (!ValidCloseBetRequest(closeBetRequest))
                {
                    ErrorMessage = ErrorEnum.ERROR_RULES_BET.ToString();
                    return(false);
                }
                if (!rouletteValidation.ValidRouletteExist(rouletteId))
                {
                    ErrorMessage = ErrorEnum.ERROR_ROULETTE_NOT_EXIST.ToString();
                    return(false);
                }
                if (!rouletteValidation.ValidRouletteIsOpen(rouletteId, rouletteModel.GetRoulettes()))
                {
                    ErrorMessage = ErrorEnum.ERROR_ROULETTE_IS_NOT_OPEN.ToString();
                    return(false);
                }

                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #2
0
        public ActionResult CloseBet(int rouletteId, [FromBody] CloseBetRequest closeBetRequest)
        {
            try
            {
                CloseBetResponse closeBetResponse = gamblingService.CloseBet(rouletteId, closeBetRequest);
                if (closeBetResponse == null && !string.IsNullOrEmpty(gamblingService.ErrorMessage))
                {
                    return(BadRequest(gamblingService.ErrorMessage));
                }

                return(Ok(closeBetResponse));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.Message));
            }
        }
Пример #3
0
 public void InsertBetResult(int betId, CloseBetRequest closeBetRequest)
 {
     try
     {
         List <BetResultEntity> betResults = GetBetResults();
         betResults.Add(new BetResultEntity
         {
             BetId  = betId,
             Number = closeBetRequest.BetResultNumber,
             Color  = closeBetRequest.BetResultColor
         });
         redisCache.SetBetResultToRedis(betResults);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Пример #4
0
        public bool ValidCloseBetRequest(CloseBetRequest closeBetRequest)
        {
            try
            {
                if (closeBetRequest.BetResultNumber < (int)RulesBetEnum.MinBetNumber || closeBetRequest.BetResultNumber > (int)RulesBetEnum.MaxBetNumber)
                {
                    return(false);
                }
                if (closeBetRequest.BetResultColor != (int)ColorBetEnum.Black && closeBetRequest.BetResultColor != (int)ColorBetEnum.Red)
                {
                    return(false);
                }

                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #5
0
 public void UpdateGamblingsToSaveResult(int betId, CloseBetRequest closeBetRequest)
 {
     try
     {
         List <GamblingEntity> objGamblings = GetGamblings();
         (from gamblings in objGamblings
          where gamblings.BetId == betId && (gamblings.BetColor == closeBetRequest.BetResultColor || gamblings.BetNumber == closeBetRequest.BetResultNumber)
          select gamblings).ToList().ForEach(g => g.WonBet = true);
         redisCache.SetGamblingToRedis(objGamblings);
         objGamblings = GetGamblings();
         (from gamblings in objGamblings
          where gamblings.BetId == betId && gamblings.WonBet == null
          select gamblings).ToList().ForEach(g => g.WonBet = false);
         redisCache.SetGamblingToRedis(objGamblings);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Пример #6
0
 public CloseBetResponse CloseBet(int rouletteId, CloseBetRequest closeBetRequest)
 {
     try
     {
         if (rouletteId == 0 || closeBetRequest == null)
         {
             ErrorMessage = ErrorEnum.ERROR_REQUEST_INCOMPLETE.ToString();
             return(null);
         }
         if (!betValidation.ValidCloseBetData(rouletteId, closeBetRequest))
         {
             ErrorMessage = betValidation.ErrorMessage;
             return(null);
         }
         return(cBet.BuilBetResponse(cBet.CloseBet(rouletteId, closeBetRequest)));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Пример #7
0
        public int CloseBet(int rouletteId, CloseBetRequest closeBetRequest)
        {
            try
            {
                if (!rouletteModel.UpdateRoulette(rouletteId, status: false))
                {
                    return(0);
                }
                BetEntity objBet = betModel.GetBets().Where(b => b.RouletteId == rouletteId && b.Status == true).FirstOrDefault();
                betModel.UpdateStatusBet(objBet.Id, status: false);
                betResultModel.InsertBetResult(objBet.Id, closeBetRequest);
                gamblingModel.UpdateGamblingsToSaveResult(objBet.Id, closeBetRequest);
                foreach (GamblingEntity gambling in gamblingModel.GetGamblings().Where(g => g.BetId == objBet.Id && g.WonBet == true).ToList())
                {
                    gamblerModel.UpdateGamblerCredits(gambling.GamblerId, gamblerModel.GetOneGambler(gambling.GamblerId).Credits + (gambling.CreditsBet * 2));
                }

                return(objBet.Id);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #8
0
        public IActionResult CloseBets([FromBody] CloseBetRequest closeBetRequest)
        {
            Entities.Roulette betResult = _betService.CloseBet(closeBetRequest.RoulettetoClose);

            return(Ok(betResult));
        }