public static PlayerModel Create(Participant participant) { string misc = participant.Misc; if (string.IsNullOrEmpty(misc)) { if (participant.Name.StartsWith("{")) { misc = participant.Name; } else { return new PlayerModel { Id = participant.Id, Name = participant.Name, Email = participant.NewUserEmail }; } } var playerModel = JsonConvert.DeserializeObject<PlayerModel>(misc); playerModel.Id = participant.Id; return playerModel; }
public ActionResult Create(TournamentModel tournamentModel) { try { if(!ModelState.IsValid) return View(new TournamentEditorViewModel(EditorAction.Create, tournamentModel)); var tournament = new Tournament(); tournament.Name = tournamentModel.Name; switch (tournamentModel.TournamentType) { case TournamentType.SingleElimination: tournament.TournamentType = "single elimination"; break; case TournamentType.DoubleElimination: tournament.TournamentType = "double elimination"; break; case TournamentType.League: tournament.TournamentType = "round robin"; break; } tournament.Url = tournamentModel.Name.Replace(" ", "_").Trim(); tournament.OpenSignup = false; if (tournamentModel.TournamentType == TournamentType.SingleElimination || tournamentModel.TournamentType == TournamentType.DoubleElimination) tournament.HoldThirdPlaceMatch = true; tournament.RoundRobinPointsForMatchTie = 1; tournament.RoundRobinPointsForMatchWin = 3; _tournamentService.Create(tournament); foreach (var player in tournamentModel.Players) { var participant = new Participant { TournamentId = tournament.Id, Name = player.Name, Misc = JsonConvert.SerializeObject(player) }; _participantService.Create(participant); } return RedirectToAction("Index"); } catch { return View(new TournamentEditorViewModel(EditorAction.Create, tournamentModel)); } }
public void Create(Participant participant) { WebClient client = new WebClient(); participant = client.Post<Participant, Participant>(string.Format("tournaments/{0}/participants.json", participant.TournamentId), participant); }