Exemplo n.º 1
0
        public async Task <IActionResult> FormatRequestAndAddMatch([FromQuery] int numOfTeams, [FromQuery] int playersPerTeam)
        {
            var createMatchRequest = new CreateMatchRequest();

            createMatchRequest.MatchType = Enum.Parse <MatchType>(Request.Form["MatchType"]);

            var formKeys = Request.Form.Keys;

            Console.WriteLine($"Key count: {formKeys.Count()}");
            var teams = new List <MatchTeam>();

            for (var i = 0; i < 2; i++)
            {
                var team = new MatchTeam();
                team.Name      = Request.Form[$"Team[{i}].Name"];
                team.TeamScore = int.Parse(Request.Form[$"Team[{i}].TeamScore"]);

                var guardianCount = formKeys.Count(g => g.Contains($"Team[{i}]") && g.Contains("GuardianName"));
                Console.WriteLine($"Guardians on team: {guardianCount}");
                var guardianResults = new List <GuardianMatchResult>();
                for (var j = 0; j < guardianCount; j++)
                {
                    var results = new GuardianMatchResult
                    {
                        Kills        = int.Parse(Request.Form[$"Team[{i}].MatchResults[{j}].Kills"]),
                        Assists      = int.Parse(Request.Form[$"Team[{i}].MatchResults[{j}].Assists"]),
                        Deaths       = int.Parse(Request.Form[$"Team[{i}].MatchResults[{j}].Deaths"]),
                        GuardianName = Request.Form[$"Team[{i}].MatchResults[{j}].GuardianName"]
                    };

                    Console.WriteLine($"Guardian results processed successfully: {results.GuardianName}");
                    if (results.Deaths == 0)
                    {
                        results.Efficiency = results.Kills + results.Assists;
                    }
                    else
                    {
                        results.Efficiency = (double)(results.Kills + results.Assists) / results.Deaths;
                    }
                    Console.WriteLine($"Calculated Eff = {results.Efficiency:F4}");
                    guardianResults.Add(results);
                }

                team.GuardianMatchResults = guardianResults;
                teams.Add(team);
            }

            createMatchRequest.Teams = teams;

            await _matchService.CreateMatch(createMatchRequest.ToMatch(), createMatchRequest.Teams);

            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
        //public ActionResult Create([ModelBinder(typeof(MatchBinder))]Match match)
        public ActionResult Create(int boardId, MatchViewModel match)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _service.CreateMatch(boardId, HttpContext.User.Identity.Name, match.Loser, match.WinnerComment,
                                         match.Tie);
                }
            }
            catch (ServiceException ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(View(new MatchViewModel
                {
                    Board = _repository.GetBoardByIdWithCompetitors(boardId),
                    Loser = match.Loser,
                    WinnerComment = match.WinnerComment,
                    Tie = match.Tie
                }));
            }

            TempData["StatusMessage"] = "Your match has been successfully reported.";

            return(RedirectToAction("List", new { boardId }));
        }
Exemplo n.º 3
0
        public void CreateNewGame(object sender, EventArgs e)
        {
            SetActivePanel(PanelType.CreateGame, "Izveidot Spēli", 185);

            ActiveMatch = _matchService.CreateMatch();

            ResetCreateGamePanel();
        }
        public List<Match> MatchFirstWay(Sport sport,Team teamOne, Team teamTwo,DateTime date,List<Match> listMatchesToReturn ){
          if(DontHaveMatchOn(date,teamOne) && DontHaveMatchOn(date,teamTwo)){  
                Match theMatch = new Match();
                theMatch.DateAndTime = date;
                theMatch.TeamOne= teamOne.TeamId;
                theMatch.TeamTwo= teamTwo.TeamId;
                theMatch.KindOfSport= sport;

                teamOne.ListOfMatches.Add(theMatch);
                teamTwo.ListOfMatches.Add(theMatch);

                teamService.UpdateTeam(teamOne.TeamId,teamOne);
                teamService.UpdateTeam(teamTwo.TeamId,teamTwo);

                matchService.CreateMatch(theMatch);
                listMatchesToReturn.Add(theMatch);
            }
            return listMatchesToReturn;
        }
Exemplo n.º 5
0
 public async Task <IActionResult> CreateMatch(CreateMatchModel createMatchModel)
 {
     try
     {
         return(Ok(await _matchService.CreateMatch(createMatchModel)));
     }
     catch (AppException ex)
     {
         return(BadRequest(new { message = ex.Message }));
     }
 }
        public async Task <IActionResult> CreateMatch([FromBody] Match match)
        {
            try
            {
                var id = await _service.CreateMatch(match);

                return(Ok(id));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.InnerException.Message));
            }
        }
Exemplo n.º 7
0
        public async Task <ActionResult <Match> > Create([FromBody] Match match)
        {
            try
            {
                var matchSaved = await _matchService.CreateMatch(match);

                _log.LogInformation($"Returning new match with id : {matchSaved.Id}");
                return(Ok(matchSaved));
            }
            catch (Exception ex)
            {
                _log.LogError($"Something went wrong: {ex}");
                return(StatusCode(500, ex));
            }
        }
        public void Create(int groupId, IRound <int, Matchup <int> > groupRound, DateTime date)
        {
            GroupRound dbGroupRound = new GroupRound
            {
                GroupId   = groupId,
                EventDate = date
            };

            _leagueContext.GroupRounds.Add(dbGroupRound);
            _leagueContext.SaveChanges();

            foreach (Matchup <int> matchup in groupRound)
            {
                _matchService.CreateMatch(dbGroupRound.Id, matchup.FirstPlayer, matchup.SecondPlayer);
            }
        }
Exemplo n.º 9
0
        public IEnumerable <Match> DoMatches(Sport sport)
        {
            List <Team>  listOfTeams         = sport.ListOfTeams;
            List <Match> listMatchesToReturn = new List <Match>();

            foreach (Team teamOne in listOfTeams)
            {
                DateTime date = DateTime.Now;
                foreach (Team teamTwo in listOfTeams)
                {
                    if (!teamOne.Equals(teamTwo))
                    {
                        if (DontHaveMatchesBetween(teamOne, teamTwo))
                        {
                            if (DontHaveMatchOn(date, teamOne) && DontHaveMatchOn(date, teamTwo))
                            {
                                Match theMatch = new Match();
                                theMatch.DateAndTime = date;
                                theMatch.TeamOne     = teamOne.TeamId;
                                theMatch.TeamTwo     = teamTwo.TeamId;
                                theMatch.KindOfSport = sport;

                                teamOne.ListOfMatches.Add(theMatch);
                                teamTwo.ListOfMatches.Add(theMatch);

                                teamService.UpdateTeam(teamOne.TeamId, teamOne);
                                teamService.UpdateTeam(teamTwo.TeamId, teamTwo);

                                matchService.CreateMatch(theMatch);
                                listMatchesToReturn.Add(theMatch);
                                date.AddDays(1);
                            }
                        }
                    }
                }
            }
            return(listMatchesToReturn);
        }
        public ActionResult CreateMatch([FromBody] Match request)
        {
            var response = _matchService.CreateMatch(request.NoOfPlayers, request.NoOfOvers);

            return(Ok(response));
        }
 private void CreateMatch(User firstPlayer, User secondPlayer)
 {
     _matchService.CreateMatch(_roundId, firstPlayer.Id, secondPlayer.Id);
 }