public ActionResult MatchInsert(int tournamentId, MatchModel match)
        {
            var tournament = _tournamentService.GetById(tournamentId);

            var newMatch = new Match();
            newMatch.Club = _tennisClubService.GetById(3);// Mapper.Map<TennisClubModel, TennisClub>(_tennisClubService.GetAll().First());
            newMatch.Club.Address = _addressService.GetById(2);
            newMatch.Player1 = _playerService.GetById(match.Player1.Id);
            newMatch.Player2 = _playerService.GetById(match.Player2.Id);
            newMatch.Stage = match.Stage;

            if (match.StartDateTime > Constants.MinimalSqlDate)
            {
                newMatch.StartDateTime = match.StartDateTime;
            }
            else
            {
                newMatch.StartDateTime = Constants.MinimalSqlDate;
            }

            ParseMatchResult(newMatch, match.MatchResultDisplay);

            _tournamentService.AddMatch(tournament, newMatch);
            return Json(tournament);
        }
        private void ParseMatchResult(Match match, string result)
        {
            if (string.IsNullOrEmpty(result))
            {
                return;
            }

            var setResults = new List<SetResult>();

            var sets = result.Trim().Split(' ');
            for (var i = 0; i < sets.Length; i++)
            {
                var set = sets[i];

                var setResult = new SetResult();
                if (set.Contains('-') && set.Split(new[] { "-" }, StringSplitOptions.RemoveEmptyEntries).Length == 2)
                {
                    setResult.Number = i + 1;
                    setResult.Player1 = match.Player1;
                    setResult.Player2 = match.Player2;
                    setResult.Player1Games = int.Parse(set.Split('-')[0]);
                    setResult.Player2Games = int.Parse(set.Split('-')[1]);

                    if (match.SetResults != null && match.SetResults.Count > i)
                    {
                        var existingSetResult = match.SetResults[i];
                        existingSetResult.CopyFrom(setResult);
                        setResults.Add(existingSetResult);
                    }
                    else
                    {
                        setResults.Add(setResult);
                    }
                }
                else
                {
                    throw new ArgumentException("Set result has wrong format");
                }
            }
            match.SetResults = setResults;
        }
 public void Delete(Match match)
 {
     match.Deleted = true;
     _matchRepository.Update(match);
 }
 public void Update(Match match)
 {
     _matchRepository.Update(match);
 }
 public void Add(Match match)
 {
     _matchRepository.Insert(match);
 }
예제 #6
0
 internal void CopyFrom(Match match)
 {
     IsTournamentMatch = match.IsTournamentMatch;
     Player1 = match.Player1;
     Player2 = match.Player2;
     SetResults = match.SetResults;
     TieBreakResult = match.TieBreakResult;
     Club = match.Club;
     CourtNumber = match.CourtNumber;
     StartDateTime = match.StartDateTime;
     Stage = match.Stage;
     Deleted = match.Deleted;
 }
 public void AddMatch(Tournament tournament, Match match)
 {
     var tournamentMatch = new TournamentMatch(tournament, match);
     _tournamentMatchRepository.Insert(tournamentMatch);
 }
        private bool MatchIsCompleted(Match match)
        {
            var isCompleted = match.WinnerId != 0;
            if (!isCompleted && match.SetResults != null && match.SetResults.Any())
            {
                var player1Sets = match.SetResults.Where(r => r.Player1Games > r.Player2Games).Count();
                var player2Sets = match.SetResults.Where(r => r.Player1Games < r.Player2Games).Count();

                // TODO Учесть результат для тайбрейка
                isCompleted = match.SetResults.All(r => r.IsCompleted()) && match.SetResults.Count > 1 && Math.Abs(player1Sets - player2Sets) >= 1;
            }
            return isCompleted;
        }
        public void UpdateMatch(Tournament tournament, Match match)
        {
            var tournamentMatch = _tournamentMatchRepository.Table.Where(tp => tp.Tournament.Id == tournament.Id && tp.Match.Id == match.Id).FirstOrDefault();
            if (tournamentMatch != null)
            {
                tournamentMatch.Match.CopyFrom(match);
                tournamentMatch.Tournament.CopyFrom(tournament);

                _tournamentMatchRepository.Update(tournamentMatch);
            }
        }