public DataGroupGoalsPlayers(FootballMatch match, FootballTeam team, Player player, Goal goal)
 {
     this.match  = match;
     this.team   = team;
     this.player = player;
     this._goals = goal;
 }
        public MatchResult SimulateMatch(FootballMatch match)
        {
            var field = new Field();
            const int interval = 10;
            var result = new MatchResult();
            bool team1HasBall = true;
            for (int seconds = 0; seconds < 90 * 60; seconds += interval)
            {
                bool otherTeamWinsBall = Random.Next(4) == 0;
                if (otherTeamWinsBall)
                    team1HasBall = !team1HasBall;
                int widthDelta = GetWidthDelta(field);
                int lengthDelta = GetLengthDelta(field, team1HasBall);
                field.MoveBall(widthDelta, lengthDelta);
                if (field.BallIsAtGoal1())
                {
                    result.Goals2++;
                    field.ResetBallPosition();
                    team1HasBall = true;
                }
                if (field.BallIsAtGoal2())
                {
                    result.Goals1++;
                    field.ResetBallPosition();
                    team1HasBall = false;
                }
            }

            return result;
        }
Exemple #3
0
 public DataGroupRCPlayers(FootballMatch match, FootballTeam team, Player player, RedCard redCard)
 {
     this.match   = match;
     this.team    = team;
     this.player  = player;
     this.redCard = redCard;
 }
Exemple #4
0
 public ActionResult Edit(int id, FootballMatch footballMatch)
 {
     try
     {
         if (ModelState.IsValid)
         {
             FootballMatch match = db.FootballMatches.Find(id);
             if (TryUpdateModel(match))
             {
                 match.FirstTeam         = footballMatch.FirstTeam;
                 match.SecondTeam        = footballMatch.SecondTeam;
                 match.FirstTeamWinsOdd  = footballMatch.FirstTeamWinsOdd;
                 match.SecondTeamWinsOdd = footballMatch.SecondTeamWinsOdd;
                 match.DrawOdd           = footballMatch.DrawOdd;
                 match.ResolveTime       = footballMatch.ResolveTime;
                 TempData["message"]     = "Match data was changed!";
                 db.SaveChanges();
             }
             return(RedirectToAction("Index"));
         }
         else
         {
             return(View(footballMatch));
         }
     }
     catch (Exception e)
     {
         return(View(footballMatch));
     }
 }
        public async Task <IActionResult> PutFootballMatch(int id, FootballMatch footballMatch)
        {
            if (id != footballMatch.IdfootballMatch)
            {
                return(BadRequest());
            }

            _context.Entry(footballMatch).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FootballMatchExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <ActionResult <FootballMatch> > PostFootballMatch(FootballMatch footballMatch)
        {
            _context.FootballMatch.Add(footballMatch);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetFootballMatch", new { id = footballMatch.IdfootballMatch }, footballMatch));
        }
Exemple #7
0
        public void playMatch(FootballMatch match)
        {
            var odd1   = match.FirstTeamWinsOdd;
            var odd2   = match.SecondTeamWinsOdd;
            var odd3   = match.DrawOdd;
            var oddSum = odd1 + odd2 + odd3;
            var result = "0";

            odd1 = odd1 / oddSum;
            odd2 = odd2 / oddSum;
            odd3 = odd3 / oddSum;
            odd1 = (1 - odd1) / 2;
            odd2 = (1 - odd2) / 2;
            odd3 = (1 - odd3) / 2;
            var    random = new Random();
            double num    = random.Next(0, 100);

            num = num / 100.00;
            if (num < odd1)
            {
                result = "1";
            }
            else if (num < odd1 + odd2)
            {
                result = "2";
            }
            else
            {
                result = "3";
            }
            updateMatch(match.FootballMatchId, result);
            resolveBets(match.FootballMatchId);
        }
        public override List <FootballMatch> GetFootballMarkets(string provider)
        {
            if (string.IsNullOrEmpty(provider))
            {
                throw new ArgumentNullException("provider", "provider is null");
            }

            EnsureCorrectProvider(provider);

            List <BetfairMarket> betfairMarkets = BetfairApi.Instance.GetFootballMarkets();


            List <FootballMatch> markets = new List <FootballMatch>();

            betfairMarkets.ForEach(bm =>
            {
                FootballMatch market = new FootballMatch();
                market.Id            = bm.Id.ToString(CultureInfo.InvariantCulture);
                market.Provider      = this.Name;
                market.Title         = bm.Title;
                markets.Add(market);
            });

            return(markets);
        }
Exemple #9
0
 public DataGroupYCPlayers(FootballMatch match, FootballTeam team, Player player, YellowCard yellowCard)
 {
     this.match      = match;
     this.team       = team;
     this.player     = player;
     this.yellowCard = yellowCard;
 }
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="sender">
        /// The source of the event; typically <see cref="NavigationHelper"/>
        /// </param>
        /// <param name="e">Event data that provides both the navigation parameter passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
        /// a dictionary of state preserved by this page during an earlier
        /// session.  The state will be null the first time a page is visited.</param>
        private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            FootballMatch DataItem = await DataSource.GetItemAsync((int)e.NavigationParameter);

            ItemId = (int)e.NavigationParameter;
            if (DataItem.incident == null || DataItem.incident.deleted == true)
            {
                IncidentPanel.Visibility     = Windows.UI.Xaml.Visibility.Collapsed;
                AddIncidentButton.Visibility = Windows.UI.Xaml.Visibility.Visible;
            }
            else
            {
                IncidentPanel.Visibility     = Windows.UI.Xaml.Visibility.Visible;
                AddIncidentButton.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                AcceptButton.Visibility      = Windows.UI.Xaml.Visibility.Visible;
            }
            if (DataItem.injury == null || DataItem.injury.deleted == true)
            {
                InjuryPanel.Visibility     = Windows.UI.Xaml.Visibility.Collapsed;
                AddInjuryButton.Visibility = Windows.UI.Xaml.Visibility.Visible;
            }
            else
            {
                AddInjuryButton.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                InjuryPanel.Visibility     = Windows.UI.Xaml.Visibility.Visible;
                AcceptButton.Visibility    = Windows.UI.Xaml.Visibility.Visible;
            }
            this.DefaultViewModel["Incidents"] = DataItem;
        }
Exemple #11
0
 public ActionResult NewStepTwo(int id, FootballMatch requestMatch)
 {
     try
     {
         if (ModelState.IsValid)
         {
             FootballMatch match = db.FootballMatches.Find(id);
             if (TryUpdateModel(match))
             {
                 match.FirstTeamId  = requestMatch.FirstTeamId;
                 match.SecondTeamId = requestMatch.SecondTeamId;
                 var firstTeam  = db.Teams.Find(requestMatch.FirstTeamId);
                 var secondTeam = db.Teams.Find(requestMatch.SecondTeamId);
                 match.FirstTeam     = firstTeam;
                 match.SecondTeam    = secondTeam;
                 TempData["message"] = "Match data was changed!";
                 db.SaveChanges();
             }
             return(RedirectToAction("NewStepThree", new { id = id }));
         }
         else
         {
             return(View(requestMatch));
         }
     }
     catch (Exception e)
     {
         return(View(requestMatch));
     }
 }
Exemple #12
0
 public ActionResult New(int championshipId, DateTime resolveTime)
 {
     try
     {
         if (ModelState.IsValid)
         {
             FootballMatch match = new FootballMatch();
             match.Outcome        = "0";
             match.ChampionshipId = championshipId;
             match.Championship   = db.Championships.Find(championshipId);
             match.ResolveTime    = resolveTime;
             db.FootballMatches.Add(match);
             db.SaveChanges();
             return(RedirectToAction("NewStepTwo", new { id = match.FootballMatchId }));
         }
         else
         {
             return(RedirectToAction("New"));
         }
     }
     catch (Exception e)
     {
         return(RedirectToAction("New"));
     }
 }
Exemple #13
0
        public ActionResult Show(int id)
        {
            FootballMatch match = db.FootballMatches.Find(id);

            ViewBag.Match = match;
            return(View(match));
        }
Exemple #14
0
 public ActionResult Resolve(int id, FootballMatch requestMatch)
 {
     try
     {
         if (ModelState.IsValid)
         {
             FootballMatch match = db.FootballMatches.Find(id);
             if (TryUpdateModel(match))
             {
                 match.Outcome       = requestMatch.Outcome;
                 TempData["message"] = "Match data was changed!";
                 db.SaveChanges();
                 resolveBets(id);
             }
             return(RedirectToAction("Index"));
         }
         else
         {
             return(View());
         }
     }
     catch (Exception e)
     {
         return(View());
     }
 }
Exemple #15
0
 public DataGroupMatchPlayers(FootballMatch match, FootballTeam team, Player player)
 {
     this.match          = match;
     this.team           = team;
     this.player         = player;
     this.matchPlayer    = new MatchPlayer(-1, -1, -1, -1);
     this.showProperties = false;
 }
Exemple #16
0
        public async Task LoadState()
        {
            DeleteButtonEd.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            FootballMatch Data = await DataSource.GetItemAsync(activId);

            dataGroupsRCPlayer = new ObservableCollection <DataGroupRCPlayers>();
            foreach (RedCard mp in Data.redcards)
            {
                DataGroupRCPlayers dp = null;
                if (mp.objectStatus != (int)DataSource.status.Deleted || mp.objectStatus != (int)DataSource.status.needDelete)
                {
                    if (mp.Team_idValue == Data.team1.id)
                    {
                        var matches = Data.team1_players.Where((player) => player.id.Equals(mp.Player_idValue));
                        if (matches.Count() > 0)
                        {
                            dp           = new DataGroupRCPlayers(Data, Data.team1, matches.First(), mp);
                            dp.firstTeam = true;
                        }
                    }
                    else
                    {
                        var matches = Data.team2_players.Where((player) => player.id.Equals(mp.Player_idValue));
                        if (matches.Count() > 0)
                        {
                            dp           = new DataGroupRCPlayers(Data, Data.team2, matches.First(), mp);
                            dp.firstTeam = false;
                        }
                    }
                    if (dp != null)
                    {
                        dataGroupsRCPlayer.Add(dp);
                    }
                }
            }
            this.DefaultViewModel["Match"] = Data;
            if (dataGroupsRCPlayer.Count() > 0)
            {
                this.DefaultViewModel["ActivElement"]          = dataGroupsRCPlayer.First();
                this.DefaultViewModel["dataGroupsMatchPlayer"] = dataGroupsRCPlayer;
                this.DefaultViewModel["Team1MatchPlayers"]     = dataGroupsRCPlayer.Where((team) => team.team.id.Equals(Data.team1.id));
                this.DefaultViewModel["Team2MatchPlayers"]     = dataGroupsRCPlayer.Where((team) => team.team.id.Equals(Data.team2.id));
            }
            if (TeamComboBox.SelectedIndex == 0)
            {
                if (this.DefaultViewModel.ContainsKey("Team1MatchPlayers"))
                {
                    mainListView.ItemsSource = this.DefaultViewModel["Team1MatchPlayers"];
                }
            }
            else
            {
                if (this.DefaultViewModel.ContainsKey("Team2MatchPlayers"))
                {
                    mainListView.ItemsSource = this.DefaultViewModel["Team2MatchPlayers"];
                }
            }
        }
Exemple #17
0
        public ActionResult Delete(int id)
        {
            FootballMatch match = db.FootballMatches.Find(id);

            db.FootballMatches.Remove(match);
            TempData["message"] = "Match was deleted!";
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Exemple #18
0
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="sender">
        /// The source of the event; typically <see cref="NavigationHelper"/>
        /// </param>
        /// <param name="e">Event data that provides both the navigation parameter passed to
        /// <see cref="Frame.Navigate(Type, object)"/> when this page was initially requested and
        /// a dictionary of state preserved by this page during an earlier
        /// session.  The state will be null the first time a page is visited.</param>
        private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            try
            {
                await DataSource.RefreshAccessToken();
            }
            catch (Exception ex)
            {
            }
            FootballMatch item = await DataSource.GetItemAsync((int)e.NavigationParameter);

            prevRoundId = item.round_id;
            this.DefaultViewModel["Item"] = item;
        }
Exemple #19
0
        public ActionResult FootballMatch(int id, int Amount)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var           oddChoice     = Request.Form["OddChoice"];
                    Bet           bet           = new Bet();
                    var           userId        = User.Identity.GetUserId();
                    FootballMatch footballMatch = db.FootballMatches.Find(id);
                    bet.UserId  = userId;
                    bet.MatchId = id;
                    switch (oddChoice)
                    {
                    case "1":
                        bet.Odd = footballMatch.FirstTeamWinsOdd;
                        break;

                    case "2":
                        bet.Odd = footballMatch.SecondTeamWinsOdd;
                        break;

                    case "3":
                        bet.Odd = footballMatch.DrawOdd;
                        break;
                    }
                    bet.OutcomeChoice   = int.Parse(oddChoice);
                    bet.Amount          = Amount;
                    bet.FirstPlayer     = footballMatch.FirstTeam.TeamName;
                    bet.SecondPlayer    = footballMatch.SecondTeam.TeamName;
                    bet.Committed       = false;
                    bet.MatchedResolved = false;
                    bet.ResolveTime     = footballMatch.ResolveTime;
                    bet.FootballMatch   = footballMatch;
                    db.Bets.Add(bet);
                    db.SaveChanges();
                    TempData["message"] = "Bet was added!";
                    return(RedirectToAction("Index", "Match"));
                }
                else
                {
                    return(View(id));
                }
            }
            catch (Exception e)
            {
                return(View(id));
            }
        }
Exemple #20
0
        static void Main(string[] args)
        {
            FootballTeam barcelona  = new FootballTeam("Barcelona");
            FootballTeam realMadrid = new FootballTeam("Real Madrid");

            for (int i = 0; i < 11; i++)
            {
                barcelona.AddRandomPlayers();
                realMadrid.AddRandomPlayers();
            }
            FootballMatch match = new FootballMatch(barcelona, realMadrid);

            match.StartMatch();
            Console.ReadKey();
        }
Exemple #21
0
        public ActionResult FootballMatch(int id)
        {
            FootballMatch match = db.FootballMatches.Find(id);

            ViewBag.Match = match;
            var user = db.Profiles.Find(User.Identity.GetUserId());

            ViewBag.User = user;
            var matches = db.FootballMatches.Where(x => x.Outcome != "0");

            matches             = matches.Where(x => (x.FirstTeamId == match.FirstTeamId && x.SecondTeamId == match.SecondTeamId) || (x.FirstTeamId == match.SecondTeamId && x.SecondTeamId == match.FirstTeamId));
            ViewBag.PastMatches = matches;
            ViewBag.HasHistory  = matches.Count() > 0;
            return(View());
        }
 private MatchDto ToDto(FootballMatch match)
 {
     return(new MatchDto
     {
         Id = match.Id,
         AwayGoals = match.AwayGoals,
         AwayTeam = match.AwayTeam,
         AwayTeamId = match.AwayTeamId,
         CompetitionId = match.CompetitionId,
         Group = match.Group,
         HomeGoals = match.HomeGoals,
         HomeTeam = match.HomeTeam,
         HomeTeamId = match.HomeTeamId,
         MatchDay = match.MatchDay,
         StartTime = match.StartTime,
         Status = match.Status
     });
 }
        public void EvaluateMatch_EvenMatch_EvenProbabilities()
        {
            var match = new FootballMatch();
            EvaluationResult evaluationResult =
                _evaluationService.EvaluateMatch(match);

            Assert.NotNull(evaluationResult);
            double firstTeamWins =
                evaluationResult.GetWinnerProbability(Winner.FirstTeam);
            double secondTeamWins =
                evaluationResult.GetWinnerProbability(Winner.SecondTeam);
            double draw =
                evaluationResult.GetWinnerProbability(Winner.Draw);

            Assert.Less(Math.Abs(firstTeamWins - secondTeamWins), 0.1d);
            Assert.Less(
                Math.Abs(firstTeamWins + secondTeamWins + draw - 1d),
                0.000001d);
        }
Exemple #24
0
 public async Task PersistMatch(FootballMatch match, CancellationToken cancellationToken)
 {
     try
     {
         _logger.LogInformation($"Persisting match: {match.Id}");
         await _producer.ProduceAsync
         (
             _topicName,
             new Message <int, string>
         {
             Key = match.Id, Value = JsonSerializer.Serialize(match)
         },
             cancellationToken
         );
     }
     catch (ProduceException <int, string> e)
     {
         _logger.LogError($"Cannot persist football match: {match.Id}.  Because: {e.Message}.");
     }
 }
        public EvaluationResult EvaluateMatch(FootballMatch match)
        {
            var result = new EvaluationResult();
            const int numberOfSimulations = 100;
            for (int simulationIndex = 0;
                simulationIndex < numberOfSimulations;
                simulationIndex++)
            {
                MatchResult matchResult = _simulationEngine.SimulateMatch(match);
                result.AddResult(matchResult);
            }

            foreach (ResultProbability resultProbability in
                result.Results.OrderByDescending(r => r.Count))
            {
                Console.WriteLine(resultProbability);
            }

            return result;
        }
Exemple #26
0
        public void resolveBets(int matchId)
        {
            FootballMatch match    = db.FootballMatches.Find(matchId);
            var           bets     = db.Bets.Where(x => x.MatchId == matchId && x.Committed == true);
            IList <Bet>   betsList = bets.ToList();

            foreach (Bet bet in betsList)
            {
                updateBet(bet.BetId, bet.OutcomeChoice.ToString() == match.Outcome);
                if (bet.OutcomeChoice.ToString() == match.Outcome)
                {
                    var amount = bet.Amount * bet.Odd;
                    awardBetcoins(amount, bet.UserId);
                }
                else
                {
                    addToPrizePool(bet.Amount);
                }
            }
        }
        public void HostsWin()
        {
            //Arrnage
            MatchRegulations matchRegulations = new MatchRegulations();
            FootballMatch match = new FootballMatch()
            {
                HostTeam = "Poland",
                GuestTeam = "Germany",
                NumberOfGoalsScoredByHosts = 2,
                NumberOfGoalsScoredByGuests = 0
            };
            TeamResultsSummary hostTeam = new TeamResultsSummary()
            {
                Team = "Poland",
                GoalsLost = 0,
                GoalsScored = 0,
                Points = 0
            };
            TeamResultsSummary guestTeam = new TeamResultsSummary()
            {
                Team = "Germany",
                GoalsLost = 0,
                GoalsScored = 0,
                Points = 0
            };

            //Act
            matchRegulations.AddPointsAndGoals(match, hostTeam, guestTeam);

            Assert.That(hostTeam.Points == 3);
            Assert.That(hostTeam.GoalsScored == 2);
            Assert.That(hostTeam.GoalsLost == 0);

            Assert.That(guestTeam.Points == 0);
            Assert.That(guestTeam.GoalsScored == 0);
            Assert.That(guestTeam.GoalsLost == 2);
        }
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="sender">
        /// The source of the event; typically <see cref="NavigationHelper"/>
        /// </param>
        /// <param name="e">Event data that provides both the navigation parameter passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
        /// a dictionary of state preserved by this page during an earlier
        /// session.  The state will be null the first time a page is visited.</param>
        private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            try
            {
                loadingRectangle.Visibility = Windows.UI.Xaml.Visibility.Visible;
                synchProgressRing.IsActive  = true;
                FootballMatch Data = await DataSource.GetItemAsync((int)e.NavigationParameter);

                activId = (int)e.NavigationParameter;
                if (Data != null)
                {
                    this.DefaultViewModel["MatchInfo"] = Data;
                }
                ObservableCollection <int> scoreValue = new ObservableCollection <int>();
                for (int i = 0; i <= 40; i++)
                {
                    scoreValue.Add(i);
                }
                this.DefaultViewModel["scoreValue"] = scoreValue;
                this.DefaultViewModel["_timePart"]  = new ConcTime(Data.start_at, Data);
                //Goals1ComboBoxEd.ItemsSource = this.DefaultViewModel["scoreValue"];
                //Goals2ComboBoxEd.ItemsSource = this.DefaultViewModel["scoreValue"];
                //penalty1ComboBoxEd.ItemsSource = this.DefaultViewModel["scoreValue"];
                //penalty2ComboBoxEd.ItemsSource = this.DefaultViewModel["scoreValue"];
                //dpFromDate.Date = DateTime.Parse(Data.start_at);
                ///dpFromDate.
                //ObservableColletcion scoreValue = new ObservableColletcion;
            }
            catch (Exception ex)
            {
            }
            finally
            {
                loadingRectangle.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                synchProgressRing.IsActive  = false;
            }
        }
        private async void AcceptButtonEd_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                synchProgressRing.IsActive  = true;
                loadingRectangle.Visibility = Windows.UI.Xaml.Visibility.Visible;
                if (PlayerComboBoxEd.SelectedItem != null && TeamComboBoxEd.SelectedItem != null)
                {
                    if (PlayerComboBoxEd.SelectedItem.GetType().Equals(typeof(Player)))
                    {
                        if (editorPanel.Tag.ToString() == "Edit")
                        {
                            Player       p = (Player)PlayerComboBoxEd.SelectedItem;
                            FootballTeam ft;
                            if (TeamComboBoxEd.SelectedIndex == 0)
                            {
                                ft = ((FootballMatch)this.DefaultViewModel["Match"]).team1;
                                ActiveDataGroupGoalItem.firstTeam = true;
                            }
                            else
                            {
                                ft = ((FootballMatch)this.DefaultViewModel["Match"]).team2;
                                ActiveDataGroupGoalItem.firstTeam = false;
                            }
                            ActiveDataGroupGoalItem.goal.Player_idValue = p.id;
                            ActiveDataGroupGoalItem.player            = p;
                            ActiveDataGroupGoalItem.team              = ft;
                            ActiveDataGroupGoalItem.goal.Team_idValue = ft.id;
                            int iM  = 0;
                            int iAM = 0;
                            try
                            {
                                iM  = Int32.Parse(MinuteTextBox.Text);
                                iAM = Int32.Parse(AdditionMinuteTextBox.Text);
                            }
                            catch
                            {
                                iM  = 0;
                                iAM = 0;
                            }
                            ActiveDataGroupGoalItem.goal.MinuteValue          = iM;
                            ActiveDataGroupGoalItem.goal.Addition_minuteValue = iAM;
                            if (AssistantComboBoxEd.SelectedIndex != -1)
                            {
                                ActiveDataGroupGoalItem.goal.Assistant_idValue = ((Player)AssistantComboBoxEd.SelectedItem).id;
                            }
                            else
                            {
                                ActiveDataGroupGoalItem.goal.Assistant_idValue = 0;
                            }
                            ActiveDataGroupGoalItem.goal.Is_penaltyValue  = (bool)IsPenaltyEd.IsChecked;
                            ActiveDataGroupGoalItem.goal.Is_autogoalValue = (bool)IsAutogoalEd.IsChecked;
                            ActiveDataGroupGoalItem.goal.objectStatus     = (int)DataSource.status.needUpdate;
                            await ActiveDataGroupGoalItem.goal.Update();
                        }
                        else
                        {
                            FootballTeam ft;
                            bool         first;
                            if (TeamComboBoxEd.SelectedIndex == 0)
                            {
                                ft    = ((FootballMatch)this.DefaultViewModel["Match"]).team1;
                                first = true;
                            }
                            else
                            {
                                ft    = ((FootballMatch)this.DefaultViewModel["Match"]).team2;
                                first = false;
                            }
                            int iM  = 0;
                            int iAM = 0;
                            try
                            {
                                iM  = Int32.Parse(MinuteTextBox.Text);
                                iAM = Int32.Parse(AdditionMinuteTextBox.Text);
                            }
                            catch
                            {
                                if (iM == null)
                                {
                                    iM = 0;
                                }
                                if (iAM == null)
                                {
                                    iAM = 0;
                                }
                            }
                            int t = 0;
                            if (AssistantComboBoxEd.SelectedIndex != -1)
                            {
                                t = ((Player)AssistantComboBoxEd.SelectedItem).id;
                            }

                            Goal mp = new Goal(0, ((FootballMatch)this.DefaultViewModel["Match"]).id, ft.id, ((Player)PlayerComboBoxEd.SelectedItem).id, t, (bool)IsAutogoalEd.IsChecked, (bool)IsPenaltyEd.IsChecked, iM, iAM);
                            mp.objectStatus = (int)DataSource.status.needCreate;
                            await mp.Update();

                            FootballMatch fm = await DataSource.GetItemAsync(activId);

                            if (mp.objectStatus != (int)DataSource.status.Deleted || mp.objectStatus != (int)DataSource.status.needDelete)
                            {
                                DataGroupGoalsPlayers dgm = new DataGroupGoalsPlayers(fm, ft, ((Player)PlayerComboBoxEd.SelectedItem), mp);
                                if (first)
                                {
                                    dgm.assName   = "Не было помощника";
                                    dgm.firstTeam = true;
                                    foreach (Player ass in ((FootballMatch)this.DefaultViewModel["Match"]).team1_players)
                                    {
                                        if (ass.id == dgm.goal.Assistant_idValue)
                                        {
                                            dgm.assName = ass.full_name;
                                        }
                                    }
                                }
                                else
                                {
                                    dgm.assName   = "Не было помощника";
                                    dgm.firstTeam = false;
                                    foreach (Player ass in ((FootballMatch)this.DefaultViewModel["Match"]).team2_players)
                                    {
                                        if (ass.id == dgm.goal.Assistant_idValue)
                                        {
                                            dgm.assName = ass.full_name;
                                        }
                                    }
                                }


                                //this.DefaultViewModel["Team1MatchPlayers"] = dataGroupsGoalsPlayer.Where((team) => team.team.id.Equals(fm.team1.id));
                                //this.DefaultViewModel["Team2MatchPlayers"] = dataGroupsGoalsPlayer.Where((team) => team.team.id.Equals(fm.team2.id));
                            }
                            //Frame.Navigate(typeof(MatchPlayerPage), activId);
                        }
                        viewPanel.Visibility      = Windows.UI.Xaml.Visibility.Visible;
                        editorPanel.Visibility    = Windows.UI.Xaml.Visibility.Collapsed;
                        DeleteButtonEd.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                    }
                }
                var dialog = new MessageDialog("Успешно сохранено на сервере.");
                await DataSource.Save();

                dialog.ShowAsync();
            }
            catch (Exception ex)
            {
                var dialog = new MessageDialog("Не удалось сохранить данные на сервере.");
                dialog.ShowAsync();
            }
            finally
            {
                LoadState();
                synchProgressRing.IsActive  = false;
                loadingRectangle.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                if (TeamComboBox.SelectedIndex == 0)
                {
                    if (this.DefaultViewModel.ContainsKey("Team1MatchPlayers"))
                    {
                        mainListView.ItemsSource = this.DefaultViewModel["Team1MatchPlayers"];
                    }
                }
                else
                {
                    if (this.DefaultViewModel.ContainsKey("Team2MatchPlayers"))
                    {
                        mainListView.ItemsSource = this.DefaultViewModel["Team2MatchPlayers"];
                    }
                }
            }
        }
Exemple #30
0
 public void ScheduleTransaction(FootballMatch match, int player, AllMoves move)
 {
 }
Exemple #31
0
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="sender">
        /// The source of the event; typically <see cref="NavigationHelper"/>
        /// </param>
        /// <param name="e">Event data that provides both the navigation parameter passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
        /// a dictionary of state preserved by this page during an earlier
        /// session.  The state will be null the first time a page is visited.</param>
        private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            //try
            //DeleteButtonEd.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            activId = (int)e.NavigationParameter;
            FootballMatch Data = await DataSource.GetItemAsync((int)e.NavigationParameter);

            dataGroupsMatchPlayerTeam1 = new ObservableCollection <DataGroupMatchPlayers>();
            dataGroupsMatchPlayerTeam2 = new ObservableCollection <DataGroupMatchPlayers>();
            DataGroupMatchPlayers dp = null;

            loadingRectangle.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            foreach (Player pl in Data.team1_players)
            {
                dp = new DataGroupMatchPlayers(Data, Data.team1, pl);
                foreach (MatchPlayer mp in Data.matchPlayers)
                {
                    if (dp.player.id == mp.Player_idValue)
                    {
                        dp.matchPlayer = mp;
                        if (mp.objectStatus != (int)DataSource.status.Deleted && mp.objectStatus != (int)DataSource.status.needDelete)
                        {
                            dp.showProperties = true;
                        }
                    }
                }
                if (dp.matchPlayer.IdValue == -1)
                {
                    dp.matchPlayer.Match_idValue  = Data.id;
                    dp.matchPlayer.Player_idValue = pl.id;
                    dp.matchPlayer.Team_idValue   = Data.team1.id;
                    dp.matchPlayer.TeamsheetValue = 0;
                }
                dataGroupsMatchPlayerTeam1.Add(dp);
            }
            foreach (Player pl in Data.team2_players)
            {
                dp = new DataGroupMatchPlayers(Data, Data.team2, pl);
                foreach (MatchPlayer mp in Data.matchPlayers)
                {
                    if (dp.player.id == mp.Player_idValue)
                    {
                        dp.matchPlayer = mp;
                        if (mp.objectStatus != (int)DataSource.status.Deleted && mp.objectStatus != (int)DataSource.status.needDelete)
                        {
                            dp.showProperties = true;
                        }
                    }
                }
                if (dp.matchPlayer.IdValue == -1)
                {
                    dp.matchPlayer.Match_idValue  = Data.id;
                    dp.matchPlayer.Player_idValue = pl.id;
                    dp.matchPlayer.Team_idValue   = Data.team2.id;
                    dp.matchPlayer.TeamsheetValue = 0;
                }
                dataGroupsMatchPlayerTeam2.Add(dp);
            }

            this.DefaultViewModel["Match"] = Data;
            if (dataGroupsMatchPlayerTeam1.Count() > 0)
            {
                this.DefaultViewModel["Team1MatchPlayers"] = dataGroupsMatchPlayerTeam1;
            }
            if (dataGroupsMatchPlayerTeam2.Count() > 0)
            {
                this.DefaultViewModel["Team2MatchPlayers"] = dataGroupsMatchPlayerTeam2;
            }
            TeamComboBox.SelectedIndex = 0;
        }
 public ConcTime(string DateTime, FootballMatch fm)
 {
     this.fm = fm;
     time    = DateTime.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Distinct().Last();
 }