//get current round of season - create one or get latest (if latest has already ROUND_GAMES_NUMBER games - create new one)
        private SeasonRound GetLatestSeasonRound(LeagueSeason leagueSeason)
        {
            if (Db.Database.Connection.State == System.Data.ConnectionState.Closed)
            {
                Db.Database.Connection.Open();
            }

            var round = (from n in Db.SeasonRounds where n.LeagueSeasonId == leagueSeason.LeagueSeasonId orderby n.RoundId descending select n).FirstOrDefault();

            if (round == null) //leagueSeason doesn't have rounds yet
            {
                round = new SeasonRound
                {
                    LeagueSeason   = leagueSeason,
                    LeagueSeasonId = leagueSeason.LeagueSeasonId,
                    IsFinished     = false,
                    RoundNumber    = 1,
                    GamePlayed     = 0,
                    StartDate      = DateTime.Now,
                    EndDate        = DateTime.Now,
                    LastUpdate     = DateTime.Now
                };

                Db.SeasonRounds.Add(round);
                Db.SaveChanges();

                var repo = new LogRepository();
                repo.WriteLog(Database.SystemData.Severity.Information, "Insert to SeasonRounds table new record", nameof(LeagueDataRepository),
                              "localhost", "[RoundId = " + round.RoundId + "]", "");
            }
            else if (round.GamePlayed >= ROUND_GAMES_NUMBER) //round already has maximum number of games -> should create new round
            {
                var newRound = new SeasonRound
                {
                    LeagueSeason   = leagueSeason,
                    LeagueSeasonId = leagueSeason.LeagueSeasonId,
                    IsFinished     = false,
                    RoundNumber    = round.RoundNumber + 1,
                    GamePlayed     = 0,
                    StartDate      = DateTime.Now,
                    EndDate        = DateTime.Now,
                    LastUpdate     = DateTime.Now
                };

                Db.SeasonRounds.Add(newRound);
                Db.SaveChanges();

                round = newRound;

                var repo = new LogRepository();
                repo.WriteLog(Database.SystemData.Severity.Information, "Insert to SeasonRounds table new record", nameof(LeagueDataRepository),
                              "localhost", "[RoundId = " + round.RoundId + "]", "");
            }

            Db.Database.Connection.Close();
            return(round);
        }
        public void UpdateSeasonRound(SeasonRound round)
        {
            if (Db.Database.Connection.State == System.Data.ConnectionState.Closed)
            {
                Db.Database.Connection.Open();
            }

            var roundDb = (from n in Db.SeasonRounds where n.RoundId == round.RoundId select n).FirstOrDefault();

            if (roundDb != null)
            {
                roundDb.Copy(round);
                var repo = new LogRepository();
                repo.WriteLog(Database.SystemData.Severity.Information, "Update record in SeasonRounds table", nameof(LeagueDataRepository),
                              "localhost", "[RoundId = " + roundDb.RoundId + "]", "");
            }
            Db.SaveChanges();

            Db.Database.Connection.Close();
        }
예제 #3
0
 private static bool CheckRound(SeasonRound round)
 {
     return(round.GamePlayed == round.AwayWinsCount + round.HomeWinsCount + round.DrawsCount);
 }