Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.77 KB | None | 0 0
  1.   public JsonResult MatchList(int? id)
  2.         {
  3.             string matchStr = "<h4 align=\"left\">Brackets</h4>";
  4.  
  5.             foreach(var t in db.Tournaments.Where(x =>x.EventID == id).ToList())
  6.             {
  7.                 var matchList = db.Matches.Where(x => x.TournamentID == t.TournamentID).ToList();
  8.                 matchStr += "<div class =\"card\" style = \"background-color:lightgrey\"> <h5 align=\"left\"><a href=\"/Events/Tournament/" + t.TournamentID + "\">" + t.TournamentName + "</a></h5><div>";
  9.                 if (matchList.Any())
  10.                 {
  11.                     var GFinal = (int)matchList.MaxBy(x => x.Round).First().Round;
  12.                     var LFinal = (int)matchList.MinBy(x => x.Round).First().Round;
  13.                     foreach (var m in matchList)
  14.                     {
  15.                         matchStr += "<table class=\"table table-bordered\" style=\"display: inline-block; border: solid; border-color:black; width:350px\">";
  16.                         matchStr += "<tr style=\"height:30px\"><td width=\"20%\">";
  17.                         matchStr += m.Identifier;
  18.                         matchStr += "</td><td width=\"55%\">";
  19.  
  20.                         if (m.Competitor1ID != null)
  21.                             matchStr += db.Competitors.Find(m.Competitor1ID).CompetitorName;
  22.                         else
  23.                         {
  24.                             if ((m.Round > 0) || ((m.Round < 0) && (db.Matches.Find(m.PrereqMatch1ID).Round < 0)))
  25.                                 matchStr += "Winner of ";
  26.                             else
  27.                                 matchStr += "Loser of ";
  28.                             matchStr += db.Matches.Find(m.PrereqMatch1ID).Identifier;
  29.                         }
  30.  
  31.                         matchStr += "</td><td width=\"25%\">";
  32.  
  33.  
  34.                        
  35.  
  36.                         if (m.Score1 == null)
  37.                             matchStr += "<button id=" + m.ApiID + "\" style=\"width: 100 % \" onclick=startMatch("+"m.ApiId"+")>Start</button>";
  38.                         else
  39.                             matchStr += m.Score1;
  40.                         matchStr += "</td></tr>";
  41.  
  42.  
  43.  
  44.  
  45.                         matchStr += "<tr><td>";
  46.                         if ((m.Round > 0) && (m.Round < (GFinal - 3)))
  47.                             matchStr += "W" + m.Round;
  48.                         else if ((m.Round < 0) && (m.Round > LFinal + 2))
  49.                             matchStr += "L" + Math.Abs((int)m.Round);
  50.                         else if (m.Round == GFinal)
  51.                         {
  52.                             if ((m.PrereqMatch1ID != null) && (db.Matches.Find(m.PrereqMatch1ID).Round == GFinal))
  53.                                 matchStr += "GFR";
  54.                             else
  55.                                 matchStr += "GF";
  56.                         }
  57.                         else if (m.Round == GFinal - 1)
  58.                             matchStr += "WF";
  59.                         else if (m.Round == GFinal - 2)
  60.                             matchStr += "WSF";
  61.                         else if (m.Round == GFinal - 3)
  62.                             matchStr += "WQF";
  63.                         else if (m.Round == LFinal)
  64.                             matchStr += "LF";
  65.                         else if (m.Round == LFinal + 1)
  66.                             matchStr += "LSF";
  67.                         else if (m.Round == LFinal + 2)
  68.                             matchStr += "LQF";
  69.                         matchStr += "</td><td>";
  70.  
  71.                         if (m.Competitor2ID != null)
  72.                             matchStr += db.Competitors.Find(m.Competitor2ID).CompetitorName;
  73.                         else
  74.                         {
  75.                             if ((m.Round > 0) || ((m.Round < 0) && (db.Matches.Find(m.PrereqMatch2ID).Round < 0)))
  76.                                 matchStr += "Winner of ";
  77.                             else
  78.                                 matchStr += "Loser of ";
  79.                             matchStr += db.Matches.Find(m.PrereqMatch2ID).Identifier;
  80.                         }
  81.  
  82.                         matchStr += "</td><td>";
  83.  
  84.                         if (m.Score2 == null)
  85.                             matchStr += "<button id=" + m.ApiID + "\" style=\"width: 100 % \" >Submit</button>";
  86.                         else
  87.                             matchStr += m.Score2;
  88.                         matchStr += "</td></tr></table>";
  89.                         matchStr += "<div style = \"display: inline-block; width: 5px\"></div>";
  90.                     }
  91.                     matchStr += "</div></div></br>";
  92.                 }
  93.             }
  94.  
  95.             var data = new
  96.             {
  97.                 matchTable = matchStr
  98.             };
  99.  
  100.             return Json(data, JsonRequestBehavior.AllowGet);
  101.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement