public HttpResponseMessage Get() { var pendingMatches = ExecuteQuery(new GetPendingMatchesQuery()); var registeredMatches = new List<Roster>(); foreach (var pendingMatch in pendingMatches) { try { var players = ExecuteQuery(new GetPlayersQuery(pendingMatch)); var parser = new BitsParser(players); var content = bitsClient.DownloadMatchResult(pendingMatch.BitsMatchId); if (pendingMatch.IsFourPlayer) { var parse4Result = parser.Parse4(content, pendingMatch.Team); ExecuteCommand(new RegisterMatch4Command(pendingMatch, parse4Result)); } else { var parseResult = parser.Parse(content, pendingMatch.Team); ExecuteCommand(new RegisterMatchCommand(pendingMatch, parseResult)); } registeredMatches.Add(pendingMatch); } catch (Exception e) { var message = string.Format("Unable to auto register match {0} ({1})", pendingMatch.Id, pendingMatch.BitsMatchId); ErrorSignal .FromCurrentContext() .Raise(new ApplicationException(message, e)); } } var result = registeredMatches.Select(x => new { x.Date, x.Season, x.Turn, x.BitsMatchId, x.Team, x.Location, x.Opponent }).ToArray(); if (result.Length > 0) return Request.CreateResponse(HttpStatusCode.OK, result); return Request.CreateResponse(HttpStatusCode.OK, "No matches to register"); }
private ActionResult Parse4( RegisterBitsVerifyModel model, BitsParser parser, string content, Roster roster, IEnumerable<Player> players) { Parse4Result result = parser.Parse4(content, roster.Team); var vm = new RegisterBitsResult4 { BitsMatchId = roster.BitsMatchId, TeamScore = result.TeamScore, OpponentScore = result.OpponentScore, RosterId = model.RosterId, Serie1 = result.Series.ElementAtOrDefault(0), Serie2 = result.Series.ElementAtOrDefault(1), Serie3 = result.Series.ElementAtOrDefault(2), Serie4 = result.Series.ElementAtOrDefault(3) }; ViewBag.players = players.Select(x => new PlayerViewModel(x)) .ToArray(); return View("RegisterBitsVerify4", vm); }