Example #1
0
        public RankingTableViewModel Put(int id)
        {
            Tourney tourney = tourneyBll.GetTourney(id);

            if (tourney == null)
            {
                Response.StatusCode = (int)HttpStatusCode.NotFound;
                return(null);
            }

            IEnumerable <TableRecord> tableRecords = ranking.CalculateTable(id);

            if (!tableRecords.Any())
            {
                Response.StatusCode = (int)HttpStatusCode.NotFound;
                return(null);
            }

            tableRecordBll.SaveTourneyTable(tourney.Id, tableRecords);

            StringBuilder sb = new StringBuilder();

            sb.AppendLine($"DELETE FROM [dbo].[TableRecords] WHERE [tournamentId] = {tourney.Id};");
            sb.AppendLine();
            sb.AppendLine("INSERT INTO [dbo].[TableRecords]");
            sb.AppendLine("([teamId],[tournamentId],[games],[wins],[draws],[loses],[goalsFor],[goalsAgainst],[points],[virtualPoints],[active],[position])");
            sb.AppendLine("VALUES");

            List <string> values = new List <string>();

            foreach (TableRecord tr in tableRecords)
            {
                int active = tr.Active ? 1 : 0;

                values.Add($"({tr.teamId},{tr.tourneyId},{tr.Games},{tr.Wins},{tr.Draws},{tr.Loses},{tr.GoalsFor},{tr.GoalsAgainst},{tr.Points}," +
                           $"{tr.PointsVirtual},{active},{tr.Position})");
            }

            sb.AppendLine(string.Join(",", values));

            RankingTableViewModel result = Get(tourney.Id);

            //try
            //{
            //    System.IO.File.WriteAllText("D:\\updTable.sql", sb.ToString());
            //}
            //finally
            //{
            //    result.data = sb.ToString();
            //}

            result.data = sb.ToString();

            return(result);
        }
Example #2
0
        private IEnumerable <RankingTableViewModel> GetRankingTable()
        {
            int     tourneyId = MainCfg.MainTableTourneyId;
            Tourney tourney   = tourneyBll.GetTourney(tourneyId);

            if (tourney == null)
            {
                Response.StatusCode = (int)HttpStatusCode.NotFound;
                logger.LogWarning("Ranking table of tourney ID='{0}' is not found!", tourneyId);
                return(null);
            }

            string tourneyName = tourney?.Name ?? string.Empty;

            tableRecordBll.FillTeams = true;
            RankingTableViewModel mainTable = tableRecordBll.GetTourneyTable(tourneyId).ToViewModel(tourneyName);

            return(new RankingTableViewModel[] { mainTable });
        }