예제 #1
0
 public void Dodaj(PlaysHistory history)
 {
     if (_context.Histories.Where(h => h.DrabinkaId == history.DrabinkaId).Count() < 2)
     {
         _context.Histories.Add(history);
         _context.SaveChanges();
     }
 }
예제 #2
0
        public IActionResult UploadGameStats(int id, int team1Id, int team2Id, int TournamentId, int TournamentLevel)
        {
            const int punkty_za_1_miejsce = 100;
            const int punkty_za_2_miejsce = 50;
            const int punkty_za_3_miejsce = 25;
            const int punkty_za_udzial    = 10;

            Drabinka drabinka = _drabinkaCtx.Drabinki.Where(d => d.Id == id).First();

            _drabinkaCtx.Aktualizuj(drabinka, TournamentId, TournamentLevel);

            PlaysHistory TeamHistory1 = new PlaysHistory
            {
                Drabinka = drabinka,
                Player   = _context.Teams.Include(l => l.TeamLeader).Where(t => t.Id == drabinka.Team1_Id).First().TeamLeader,
                TeamId   = drabinka.Team1_Id,
                TeamName = drabinka.Team1_Name,
                Status   = drabinka.Team1_Win
            };

            _historyCtx.Dodaj(TeamHistory1);

            PlaysHistory TeamHistory2 = new PlaysHistory
            {
                Drabinka = drabinka,
                Player   = _context.Teams.Include(l => l.TeamLeader).Where(t => t.Id == drabinka.Team2_Id).First().TeamLeader,
                TeamId   = drabinka.Team2_Id,
                TeamName = drabinka.Team2_Name,
                Status   = drabinka.Team2_Win
            };

            _historyCtx.Dodaj(TeamHistory2);

            //punkty za zajecia vice 3 miejsca
            if (TournamentLevel == 1)
            {
                if (TeamHistory1.Status == false)
                {
                    _teamCtx.PrzydzielPunkty(TeamHistory1.TeamId, punkty_za_udzial);
                    _teamCtx.UploadTeamParticipate(TeamHistory1.TeamId);
                }

                if (TeamHistory2.Status == false)
                {
                    _teamCtx.PrzydzielPunkty(TeamHistory2.TeamId, punkty_za_udzial);
                    _teamCtx.UploadTeamParticipate(TeamHistory2.TeamId);
                }
            }
            if (TournamentLevel == 2)
            {
                if (TeamHistory1.Status == false)
                {
                    _teamCtx.PrzydzielPunkty(TeamHistory1.TeamId, punkty_za_3_miejsce);
                    _teamCtx.UploadTeamParticipate(TeamHistory1.TeamId);
                }

                if (TeamHistory2.Status == false)
                {
                    _teamCtx.PrzydzielPunkty(TeamHistory2.TeamId, punkty_za_3_miejsce);
                    _teamCtx.UploadTeamParticipate(TeamHistory2.TeamId);
                }
            }
            //Przydzielenie punktów za pierwsze 1 i 2 miejsca
            if (TournamentLevel == 3)
            {
                if (TeamHistory1.Status == true)
                {
                    _teamCtx.PrzydzielPunkty(TeamHistory1.TeamId, punkty_za_1_miejsce);
                    _teamCtx.UploadTeamParticipate(TeamHistory1.TeamId);
                    _teamCtx.SaveWinInTournament(TeamHistory1.TeamId);
                }
                else if (TeamHistory1.Status == false)
                {
                    _teamCtx.PrzydzielPunkty(TeamHistory1.TeamId, punkty_za_2_miejsce);
                    _teamCtx.UploadTeamParticipate(TeamHistory1.TeamId);
                }

                if (TeamHistory2.Status == true)
                {
                    _teamCtx.PrzydzielPunkty(TeamHistory2.TeamId, punkty_za_1_miejsce);
                    _teamCtx.UploadTeamParticipate(TeamHistory2.TeamId);
                    _teamCtx.SaveWinInTournament(TeamHistory2.TeamId);
                }
                else if (TeamHistory2.Status == false)
                {
                    _teamCtx.PrzydzielPunkty(TeamHistory2.TeamId, punkty_za_2_miejsce);
                    _teamCtx.UploadTeamParticipate(TeamHistory2.TeamId);
                }
            }
            return(RedirectToAction("DetailNew", new { id = TournamentId }));
        }