Esempio n. 1
0
        public static IEnumerable<DetailTableView> GetLatestDetailedTable()
        {
            string connectionString = ConfigurationManager.ConnectionStrings["HetEKSpelEntities"].ConnectionString;
            HetEKSpelEntities db = new HetEKSpelEntities(connectionString);

            var latestTableId = Standen.GetLatestTableId();

            var table = db.Tables.Where(t => t.TableId == latestTableId);

            var participants = from it in db.Participants
                               select it;

            var list = participants.ToList();

            var detailedTableView = new List<DetailTableView>();

            foreach (var line in table)
            {
                var newLine = new DetailTableView()
                                  {
                                      Id =line.Id,
                                      ParticipantId = line.ParticipantId,
                                      Position = line.Position,
                                      ParticipantName = list.SingleOrDefault(p => p.Id == line.ParticipantId).Name,
                                      TotalPoints = line.TotalPoints,
                                      PouleA = line.PouleA,
                                      PouleB = line.PouleB,
                                      PouleC = line.PouleC,
                                      PouleD = line.PouleD,
                                      PouleTables = line.Table1,
                                      QuarterFinal = line.QuarterFinals,
                                      SemiFinal = line.SemiFinals,
                                      Final = line.Finals,
                                      Winner = line.Winner
                                  };

                detailedTableView.Add(newLine);
            }

            return detailedTableView;
        }
Esempio n. 2
0
        public static IEnumerable<DetailTableView> GetLatestGameTable()
        {
            string connectionString = ConfigurationManager.ConnectionStrings["HetEKSpelEntities"].ConnectionString;
            HetEKSpelEntities db = new HetEKSpelEntities(connectionString);

            var latestTableId = Standen.GetLatestTableId();

            var table = db.Tables.Where(t => t.TableId == latestTableId);

            var participants = from it in db.Participants
                               select it;

            var list = participants.ToList();

            var detailedTableView = new List<DetailTableView>();

            foreach (var line in table)
            {
                var newLine = new DetailTableView()
                {
                    Id = line.Id,
                    ParticipantId = line.ParticipantId,
                    Position = line.Position,
                    ParticipantName = list.SingleOrDefault(p => p.Id == line.ParticipantId).Name,
                    TotalPoints = line.PouleA + line.PouleB + line.PouleC + line.PouleD,
                    PouleA = line.PouleA,
                    PouleB = line.PouleB,
                    PouleC = line.PouleC,
                    PouleD = line.PouleD
                };

                detailedTableView.Add(newLine);
            }
            var orderedTable = detailedTableView.OrderByDescending(d => d.TotalPoints);

                        //Add position to Table
            var position = 0;
            var previous = -1;

            foreach (var standLine in orderedTable)
            {
                if (position == 0)
                {
                    position++;
                    standLine.Position = position;
                }
                else
                {

                    if (orderedTable.ElementAt(previous).TotalPoints == standLine.TotalPoints)
                    {
                        standLine.Position = position;
                    }

                    else
                    {
                        position = previous + 2;
                        standLine.Position = position;
                    }
                }

                previous++;

            }
            return orderedTable;
        }