Пример #1
0
        public ApiWrapperResponse <IList <RouletteInfo> > GetRoulettes(CreateBetRequest request)
        {
            LogInfo("Start GetRoulettes");
            ApiWrapperResponse <IList <RouletteInfo> > result = new ApiWrapperResponse <IList <RouletteInfo> >(new List <RouletteInfo>(), 1);

            try {
                var list_of_values      = new List <RouletteInfo>();
                var rouletes            = RouletteModel.GetRoulettes();
                var betboardsdictionary = RouletteModel.GetRoulettesBoards();

                list_of_values = rouletes.Select(roulette => {
                    RouletteInfo info           = new RouletteInfo();
                    info.Roulette               = roulette;
                    List <BetBoard> list_result = null;
                    betboardsdictionary.TryGetValue(roulette.id.ToString(), out list_result);
                    info.BetBoardList = list_result;
                    return(info);
                }).ToList();
                result = new ApiWrapperResponse <IList <RouletteInfo> >(list_of_values, 1);
            }
            catch (Exception ex) {
                result = new ApiWrapperResponse <IList <RouletteInfo> >(1);
                LogException("Error GetRoulettes ", ex);
            }
            LogInfo("End GetRoulettes " + result.ToString());
            return(result);
        }
Пример #2
0
        public ApiWrapperResponse <Bet> CloseTheRoulette(string serial)
        {
            LogInfo("Start CloseTheRoulette");
            ApiWrapperResponse <Bet> result = new ApiWrapperResponse <Bet>(null, 1);

            try {
                var bet_winner = RouletteModel.CloseRoulette(serial);
                result = new ApiWrapperResponse <Bet>(bet_winner, bet_winner != null? 0 : 1);
                if (bet_winner != null)
                {
                    //In this implementation you can only bet by the number and by the color.
                    //so the amount of the player is increased by the values stated in the especification
                    var winner_by_color  = 1.8m;
                    var winner_by_number = 5m;
                    var new_amount       = bet_winner.BetAmount * winner_by_color + bet_winner.BetAmount * winner_by_number;
                    RouletteModel.AddCreditToThePlayer(bet_winner.PlayerId, new_amount);
                }
            }
            catch (Exception ex) {
                result = new ApiWrapperResponse <Bet>(1);
                LogException("Error CloseTheRoulette ", ex);
            }
            LogInfo("End CloseTheRoulette " + result.ToString());
            return(result);
        }
Пример #3
0
        public ApiWrapperResponse <string> CreateRoulette()
        {
            LogInfo("Start CreateRoulette");
            ApiWrapperResponse <string> result = new ApiWrapperResponse <string>("", 1);

            try {
                var new_roulette_serial = RouletteModel.CreateRoullete();
                result = new  ApiWrapperResponse <string>(new_roulette_serial, 0);
            }catch (Exception ex) {
                result = new ApiWrapperResponse <string>(1);
                LogException("Error CreateRoulette ", ex);
            }
            LogInfo("End CreateRoulette " + result.ToString());
            return(result);
        }
Пример #4
0
        public ApiWrapperResponse <bool> OpenRoulette(string serial)
        {
            LogInfo("Start OpenRoulette");
            ApiWrapperResponse <bool> result = new ApiWrapperResponse <bool>(false, 1);

            try {
                RouletteModel.OpenRoulette(serial);
            }
            catch (InvalidOperationException ex) {
                result = new ApiWrapperResponse <bool>(1, ex.Message);
            }
            catch (Exception ex) {
                result = new ApiWrapperResponse <bool>(1);
                LogException("Error OpenRoulette ", ex);
            }
            LogInfo("End OpenRoulette " + result.ToString());
            return(result);
        }
Пример #5
0
        public ApiWrapperResponse <string> CreateBet(CreateBetRequest CreateBetRequest)
        {
            LogInfo("Start CreateBet");
            ApiWrapperResponse <string> result = new ApiWrapperResponse <string>("", 1);

            try {
                StringValues player_id = "";
                //this header must be encrypted
                HttpContext.Request.Headers.TryGetValue("PlayerIdentification", out player_id);
                if (StringValues.IsNullOrEmpty(player_id))
                {
                    result = new ApiWrapperResponse <string>(1, "Invalid Request the player header does not exits.");
                }
                else
                {
                    CreateBetRequest.bet.AssingPlayerId(player_id);
                    if (RouletteModel.PlayerHasCredit(CreateBetRequest.bet))
                    {
                        RouletteModel.AddBet(CreateBetRequest.id_roulette, CreateBetRequest.bet);
                    }
                    else
                    {
                        result = new ApiWrapperResponse <string>("Player does not have credit to make the Bet.", 1);
                    }
                }
            }
            catch (BetBoardStateException ex) {
                result = new ApiWrapperResponse <string>(1, ex.Message);
                LogException("Error CreateBet ", ex);
            }
            catch (Exception ex) {
                result = new ApiWrapperResponse <string>(1);
                LogException("Error CreateBet ", ex);
            }
            LogInfo("End CreateBet " + result.ToString());
            return(result);
        }