Ejemplo n.º 1
0
        public void UpdateMatchResult(MatchScoreUpdateInfo scoreUpdateInfo)
        {
            UseDataContext(
                dataContext =>
            {
                var match = dataContext.Matches.FirstOrDefault(m => m.Id == scoreUpdateInfo.MatchId);
                if (match == null)
                {
                    throw new ArgumentException(
                        "Match '{0}' could not be found, could not update score.".ParseTemplate(
                            scoreUpdateInfo.MatchId));
                }

                if (scoreUpdateInfo.Winner.HasValue)
                {
                    match.Winner = scoreUpdateInfo.Winner.Value == MatchWinner.None
                                               ? default(int?)
                                               : (int)scoreUpdateInfo.Winner.Value;

                    if (match.Winner.HasValue)
                    {
                        match.Status = (int)MatchStatus.Completed;
                    }
                }
                if (scoreUpdateInfo.Result.HasValue)
                {
                    match.Result = (int)scoreUpdateInfo.Result.Value;
                }

                dataContext.SubmitChanges();
            });
        }
Ejemplo n.º 2
0
        private void UpdateScores(MatchResultUpdateModel[] updates, ICompetitionsManager manager)
        {
            var matchScoreUpdateInfoItems = new List <MatchScoreUpdateInfo>();

            updates.ForEach(update =>
            {
                var matchScoreUpdateInfo = new MatchScoreUpdateInfo();

                matchScoreUpdateInfo.MatchId = update.Id;
                matchScoreUpdateInfo.Result  = update.Result;
                matchScoreUpdateInfo.Winner  = update.Winner;

                matchScoreUpdateInfoItems.Add(matchScoreUpdateInfo);
                if (update.SetScores.NotNullOrEmpty())
                {
                    var scores =
                        update.SetScores.Where(s => !(s.Player1Points == 0 && s.Player2Points == 0));
                    if (scores.NotNullOrEmpty())
                    {
                        matchScoreUpdateInfo.SetScores = update.SetScores;
                    }
                }
            });
            if (matchScoreUpdateInfoItems.NotNullOrEmpty())
            {
                manager.UpdateMatchScore(matchScoreUpdateInfoItems.ToArray());
            }
        }
Ejemplo n.º 3
0
        public void UpdateMatchScore(MatchScoreUpdateInfo scoreUpdateInfo)
        {
            if (scoreUpdateInfo.SetScores.IsNullOrEmpty())
            {
                throw new ArgumentException("You must specify set scores.");
            }
            lock (m_lock)
            {
                UseDataContext(
                    dataContext =>
                {
                    var matchId       = scoreUpdateInfo.MatchId;
                    var dataSetScores = new Dictionary <int, MatchScore>();
                    scoreUpdateInfo.SetScores.ForEach(
                        setScore =>
                    {
                        var dataSetScore =
                            dataContext.MatchScores.FirstOrDefault(ms => ms.MatchId == matchId && ms.SetNumber == setScore.Number);
                        if (dataSetScore == null)
                        {
                            if (!dataSetScores.TryGetValue(setScore.Number, out dataSetScore))
                            {
                                dataSetScore           = new MatchScore();
                                dataSetScore.SetNumber = setScore.Number;
                                dataSetScore.MatchId   = matchId;
                                dataSetScore.Match     = dataContext.Matches.First(m => m.Id == matchId);
                                dataContext.MatchScores.InsertOnSubmit(dataSetScore);

                                dataSetScores[setScore.Number] = dataSetScore;
                            }
                            dataSetScore.SetNumber = setScore.Number;
                            if (setScore.Player1Points.HasValue)
                            {
                                dataSetScore.Player1Points = setScore.Player1Points.Value;
                            }
                            if (setScore.Player2Points.HasValue)
                            {
                                dataSetScore.Player2Points = setScore.Player2Points.Value;
                            }
                            if (setScore.BreakPoints.HasValue)
                            {
                                dataSetScore.BreakPoints = setScore.BreakPoints.Value;
                            }
                            if (
                                dataSetScore.Match.Status < (int)MatchStatus.Playing)
                            {
                                dataSetScore.Match.Status = (int)MatchStatus.Playing;
                            }
                        }
                    });

                    dataContext.SubmitChanges();

                    var match = dataContext.Matches.FirstOrDefault(m => m.Id == matchId);
                    if (match == null)
                    {
                        throw new ArgumentException("Match '{0}' could not be found, could not update score.".ParseTemplate(scoreUpdateInfo.MatchId));
                    }

                    var latest = scoreUpdateInfo.SetScores.OrderByDescending(s => s.Number).First();
                    match.Id   = matchId;
                    if (latest.Player1Points.HasValue)
                    {
                        match.Player1Points = latest.Player1Points.Value;
                    }
                    if (latest.Player2Points.HasValue)
                    {
                        match.Player2Points = latest.Player2Points.Value;
                    }
                    if (latest.BreakPoints.HasValue)
                    {
                        match.BreakPoints = latest.BreakPoints.Value;
                    }

                    dataContext.SubmitChanges();
                });
            }
        }
Ejemplo n.º 4
0
        public void UpdateMatchScore(MatchScoreUpdateInfo scoreUpdateInfo)
        {
            var competitionMatchesRepository = ServiceProvider.Get <ICompetitionMatchesRepository>();

            competitionMatchesRepository.UpdateMatchScore(scoreUpdateInfo);
        }
Ejemplo n.º 5
0
        //// GET api/score
        //public IEnumerable<string> Get()
        //{
        //    return new string[] { "value1", "value2" };
        //}

        //// GET api/score/5
        //public string Get(int id)
        //{
        //    return "value";
        //}

        // POST api/score
        public void Post([FromBody] MatchScoreUpdateInfo matchInfo)
        {
            var manager = ServiceProvider.Get <ICompetitionsManager>();

            manager.UpdateMatchScore(new[] { matchInfo });
        }