Пример #1
0
        public Bet(UserDataManager manager, Match match, POCO.BetPoco poco)
        {
            Id = poco._id;
            MyMatch = match;
            MatchHash = poco.match_hash;
            UserContext = manager.User;

            SetOutcome(poco.outcome);

            if (match != null)
            {
                if (match.Player1 != null && poco.offerer_choice_id == match.Player1.Id)
                {
                    OffererChoice = match.Player1;
                    TakerChoice = match.Player2;
                }
                else
                {
                    OffererChoice = match.Player2;
                    TakerChoice = match.Player1;
                }
            }

            var offerer = new POCO.UserBase { _id = poco.offerer_id, username = poco.offerer_username };
            Offerer = manager.GetPgUser(offerer);
            OffererOdds = poco.offerer_odds;
            OffererWager = poco.offerer_wager;

            var taker = new POCO.UserBase { _id = poco.taker_id, username = poco.taker_username };
            if (!string.IsNullOrWhiteSpace(taker._id))
                Taker = manager.GetPgUser(taker);
        }
 public void OnMatchesLoaded(List<MatchPoco> matches)
 {
     foreach (var match in matches)
     {
         Match item = new Match(match);
         _matches.Add(item);
     }
     OnPropertyChanged("Matches");
 }
 public void OnWinnerReported(Match match)
 {
     if (match == null)
     {
         LoadMatches();
     }
     else
     {
         _matches.Remove(match);
         OnPropertyChanged("Matches");
     }
 }
 public void ReportMatchWinner(Match match)
 {
     _session.ReportMatchWinner(match, OnWinnerReported);
 }
        public void SetMatch(Match match)
        {
            MapName = match.Map;

            _match = match;
            var operandA = match.Player1;
            var operandB = match.Player2;

            _betOperandA = operandA;
            _betOperandB = operandB;
            UpdateSummary();
        }
 public void ReportMatchWinner(Match match, Action<Match> onCompleted)
 {
     RestResponse<ApiResponse> response = null;
     _userData.PgSession.BeginAndCallback(delegate
     {
         var url = _userData.PgSession.GetWebAppFunction("/api", "/matches/" + match.Id + ".json");
         var client = new RestClient(url);
         var request = new RestRequest(Method.PUT);
         response = (RestResponse<ApiResponse>)client.Execute<ApiResponse>(request);
     }, delegate
     {
         if (!response.IsOk())
         {
             string msg = response.Data.errors == null ? response.StatusCode.ToString() : string.Concat(response.Data.errors);
             MessageDialog.Show(_window, "Failed to report winner", msg);
             onCompleted(null);
         }
         else
         {
             onCompleted(match);
         }
     });
 }
 public void CancelBet(Bet bet)
 {
     RestResponse<ApiResponse> response = null;
     _userData.PgSession.BeginAndCallback(delegate
     {
         var url = _userData.PgSession.GetWebAppFunction("/api", "/game_rooms/" + GameRoom.Id + "/bets/" + bet.Id + ".json");
         var client = new RestClient(url);
         var request = new RestRequest(Method.DELETE);
         response = (RestResponse<ApiResponse>)client.Execute<ApiResponse>(request);
     }, delegate
     {
         if (response.IsOk())
         {
             if (MyMatch.Id == bet.MyMatch.Id && bet.MyMatch.State == MatchState.created)
             {
                 _myMatch = new Match();
             }
         }
         else
         {
             string msg = response.Data.errors == null ? response.StatusCode.ToString() : string.Concat(response.Data.errors);
             MessageDialog.Show(_window, "Failed to delete bet", msg);
         }
     });
 }
        public void UpdateMatch(Match m)
        {
            MyMatch.IsEditable = false;

            var url = _userData.PgSession.GetWebApiV1Function("/matches/" + m.Id + ".json");
            var poco = new //POCO.MatchPoco
            {
                game_id = m.GameId,
                betting = m.IsBetting,

                player_1_name = m.Player1.ShortDescription,
                player_1_type = m.Player1.PocoType,
                player_1_id = m.Player1.Id,

                player_2_name = m.Player2.ShortDescription,
                player_2_type = m.Player2.PocoType,
                player_2_id = m.Player2.Id,

                map = m.Map,
            };
            var root = new { match = poco };

            RestResponse<ApiResponse> response = null;
            _userData.PgSession.BeginAndCallback(delegate
            {
                response = SocketSession.Rest<ApiResponse>(url, Method.PUT, root);
            }, delegate
            {
                if (!response.IsOk())
                {
                    MyMatch.IsEditable = true;
                    MessageDialog.Show(_window, "Failed to update match", "Sorry, failed to update match.\r\nDetails: " + response.ErrorMessage);
                }
            });
        }
 public void OnBetNew(BetPoco poco)
 {
     Bet bet = new Bet(_userData, MyMatch, poco);
     RoomBets.Add(bet);
     _myMatch = new Match();
 }
        public void LoadBets()
        {
            if (GameRoom.Bets.Length > 0) return;

            RestResponse<List<BetPoco>> response = null;
            _userData.PgSession.BeginAndCallback(delegate
            {
                var url = _userData.PgSession.GetWebAppFunction("/api", "/game_rooms/" + GameRoom.Id + "/bets", "include_matches=true");
                var client = new RestClient(url);
                var request = new RestRequest(Method.GET);
                response = (RestResponse<List<BetPoco>>)client.Execute<List<BetPoco>>(request);
            }, delegate
            {
                if (response.IsOk())
                {
                    if (response.Data != null)
                    {
                        var bets = response.Data;
                        foreach (BetPoco bet in bets)
                        {
                            Match match = new Match(bet.match);
                            Bet item = new Bet(_userData, match, bet);
                            RoomBets.Add(item);
                        }
                    }
                }
                else
                {
                    MessageDialog.Show(_window, "Failed to get Bets", "Sorry, failed to get bet list.\r\nDetails: " + response.ErrorMessage);
                }
            });
        }