Example #1
0
        public async Task UpdateStatsInMatch(int Matchid, IEnumerable <GetPlayersStatisticInMatchDto> PlayersStats)
        {
            var playersListInMatch = await _matchRepository.GetAsyncPlayersInMatch(Matchid); //pobieram mecz a w nim liste z jakimi playerami sie łączy

            if (playersListInMatch == null)
            {
                throw new Exception($"Match with this id {Matchid} does not exist");
            }
            var matchhPlayer = _mapper.Map <IEnumerable <MatchhPlayer> >(PlayersStats);
            List <MatchhPlayer> matchhPlayerList = matchhPlayer.ToList();

            foreach (var playerS in PlayersStats)
            {
                var plr = playersListInMatch.Players2Match.SingleOrDefault(x => x.PlayerId == playerS.PlayerId);    //pobieramy zawodnika o id
                // playersListInMatch.Players2Match.Remove(plr);   //usuwamy go na chwile bo nie mozna albo nie wiem jak nadpisac
                await _matchRepository.DeleteAsyncListPlayersInMatch(Matchid, plr);

                //deklaruje obiekt tablicy posredniej
                var match = await _matchRepository.GetAsyncMatch(Matchid);                              //pobieram mecz o wskazanym id

                var player = await _playerRepository.GetAsyncPlayer(Convert.ToInt32(playerS.PlayerId)); //pobieram zawodnika o wskazanym id

                if (player != null)
                {
                    var plr2matches = new MatchhPlayer(Convert.ToInt16(playerS.Goals), Convert.ToInt16(playerS.Assists), Convert.ToInt16(playerS.YellowCard), Convert.ToInt16(playerS.RedCard), Convert.ToBoolean(playerS.PlayInMatch), match, player);
                    await _matchRepository.AddAsyncPlayerStatisticToMatch(Matchid, plr2matches);
                }
            }
            await Task.CompletedTask;
        }
        public async Task AddAsyncPlayerToMatch(int matchId, MatchhPlayer player)
        {
            var match = await GetAsyncMatch(matchId);   //pobieram mecz o wskazanym matchId

            match.Players2Match.Add(player);
            _context.SaveChanges();
            await Task.CompletedTask;
        }
        public async Task DeleteAsyncListPlayersInMatch(int id, MatchhPlayer player)
        {
            var playersListInMatch = await GetAsyncPlayersInMatch(id); //pobiera mecz z zawarta lista zawodnikow przypisana do niego

            playersListInMatch.Players2Match.Remove(player);           //jezeli jest to usuwamy i zapisujemy zmiany
            _context.SaveChanges();
            await Task.CompletedTask;
        }
        public async Task AddAsyncPlayerStatisticToMatch(int matchId, MatchhPlayer player)
        {                                             //tu dostajemy tez tablice intow czyli matchId playerow bo nie mozna bylo przeslac rzutujac na MatchPlayer
            var match = await GetAsyncMatch(matchId); //pobieram mecz a w nim liste z jakimi playerami sie łączy

            match.Players2Match.Add(player);          //tworzymy na nowo obiekt o odpowiednich matchId i z wszystkimi informacjami i ponownie ale juz uzupelnionego dodajemy do bazy
            _context.SaveChanges();

            await Task.CompletedTask;
        }
Example #5
0
        public async Task <IEnumerable <MergedPlayersStatisticsDto> > GetListPlayersStatistics(int Matchid)   // pobiera statysyki zawodnikow w konkretnym meczu
        {
            var match = await _matchRepository.GetAsyncMatch(Matchid);

            if (match == null)
            {
                throw new Exception($"Match with this id {Matchid} does not exist");
            }



            var playersListInMatch = await _matchRepository.GetAsyncPlayersInMatch(Matchid);   //pobieram mecz a w nim liste z jakimi playerami sie łączy

            var playerList = new List <MatchhPlayer>();

            for (int i = 0; i < playersListInMatch.Players2Match.Count; i++)
            {
                var player = new MatchhPlayer(Convert.ToInt16(playersListInMatch.Players2Match[i].Goals), Convert.ToInt16(playersListInMatch.Players2Match[i].Assists), Convert.ToInt16(playersListInMatch.Players2Match[i].YellowCard), Convert.ToInt16(playersListInMatch.Players2Match[i].RedCard), Convert.ToBoolean(playersListInMatch.Players2Match[i].PlayInMatch)); //wyszukuje go
                player.PlayerId = Convert.ToInt16(playersListInMatch.Players2Match[i].PlayerId);                                                                                                                                                                                                                                                                            //wybieram zawodnika dopisanego do meczu
                playerList.Add(player);                                                                                                                                                                                                                                                                                                                                     //i dodaje go do listy
            }



            List <MergedPlayersStatisticsDto> AllInfoListPlrs = new List <MergedPlayersStatisticsDto>();
            List <MatchhPlayer> playersSList = playerList.ToList();    // konwertuje ienumerable do listy zeby moc wykonac swoje dzialania

            for (int i = 0; i < playersSList.Count; i++)
            {
                MergedPlayersStatisticsDto playerStatsInMatchFull = new MergedPlayersStatisticsDto();
                var    plr    = _playerRepository.GetAsyncPlayer(Convert.ToInt16(playersSList[i].PlayerId));
                Player plaObj = plr.Result;
                playerStatsInMatchFull.PlayerId    = Convert.ToInt16(playersSList[i].PlayerId);
                playerStatsInMatchFull.Name        = plaObj.Name;
                playerStatsInMatchFull.Surname     = plaObj.Surname;
                playerStatsInMatchFull.Position    = plaObj.Position;
                playerStatsInMatchFull.Goals       = Convert.ToInt32(playersSList[i].Goals);
                playerStatsInMatchFull.Assists     = Convert.ToInt32(playersSList[i].Assists);
                playerStatsInMatchFull.YellowCard  = Convert.ToInt32(playersSList[i].YellowCard);
                playerStatsInMatchFull.RedCard     = Convert.ToInt32(playersSList[i].RedCard);
                playerStatsInMatchFull.PlayInMatch = playersSList[i].PlayInMatch;
                AllInfoListPlrs.Add(playerStatsInMatchFull);
            }

            //return _mapper.Map<IEnumerable<GetPlayersStatisticInMatchDto>>(playersS);
            AllInfoListPlrs = SortPlayers(AllInfoListPlrs);
            return(AllInfoListPlrs);
        }
Example #6
0
        public async Task AddPlayersToMatch(int MatchId, IEnumerable <int> PlayersId)    // metoda dodaje zawodnikow do meczu
        {
            var match = await _matchRepository.GetAsyncMatch(MatchId);

            if (match == null)
            {
                throw new Exception($"Match with this id {MatchId} does not exist");
            }
            //await _matchRepository.AddAsyncPlayerToMatch(MatchId,PlayersId);
            var playersListInMatch = await _matchRepository.GetAsyncPlayersInMatch(MatchId);

            foreach (int playerId in PlayersId)       //przechodze przez wszystkie id playersow ktorych chce dodac do meczu
            {
                var plr2matches = new MatchhPlayer(); //deklaruje obiekt tablicy posredniej

                bool IsInList = false;
                IsInList = playersListInMatch.Players2Match.Exists(x => x.PlayerId == playerId); // jezeli jest juz przypisany to tu zmienia na prawde

                if (IsInList == false)                                                           //dzieki temu widzimy czy nalezy jezeli falsz czyli nie to dodajemy
                {
                    var player = await _playerRepository.GetAsyncPlayer(playerId);               //pobieram zawodnika o wskazanym id

                    if (player == null)
                    {
                        continue;
                    }
                    else
                    {
                        plr2matches.Matchh = match;   //wypelniamy obiekt tabeli posredniej
                        plr2matches.Player = player;
                        await _matchRepository.AddAsyncPlayerToMatch(MatchId, plr2matches);

                        // match.Players2Match.Add(plr2matches);
                    }
                }
            }

            await Task.CompletedTask;
        }