private ActionResult Parse( RegisterBitsVerifyModel model, BitsParser parser, string content, Roster roster, Player[] players) { var result = parser.Parse(content, roster.Team); var vm = new RegisterBitsResult { 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("RegisterBitsVerify", vm); }
public ActionResult RegisterBitsVerifyConfirmed(RegisterBitsResult vm) { if (ModelState.IsValid == false) return View(vm); var roster = DocumentSession.Load<Roster>(vm.RosterId); if (roster == null) throw new HttpException(404, "Roster not found"); var matchResult = new MatchResult( roster, vm.TeamScore, vm.OpponentScore, vm.BitsMatchId); foreach (var serie in new[] { vm.Serie1, vm.Serie2, vm.Serie3, vm.Serie4 }.Where(x => x != null)) { var tables = new List<MatchTable>(); for (var i = 0; i < 4; i++) { var game1 = new MatchGame( serie.Tables[i].Game1.Player, serie.Tables[i].Game1.Pins, serie.Tables[i].Game1.Strikes, serie.Tables[i].Game1.Spares); var game2 = new MatchGame( serie.Tables[i].Game2.Player, serie.Tables[i].Game2.Pins, serie.Tables[i].Game2.Strikes, serie.Tables[i].Game2.Spares); tables.Add(new MatchTable(game1, game2, serie.Tables[i].Score)); } matchResult.RegisterSerie(new MatchSerie(tables)); } EventStoreSession.Store(matchResult); return RedirectToAction("Index", "MatchResult"); }