//create
 public ActionResult Create()
 {
     var model = new TournamentDetailsModel();
     return View(model);
 }
 public ActionResult Edit(TournamentDetailsModel model, bool continueEditing)
 {
     var tournament = model.GeneralInfo.ToEntity();
     _tournamentService.Update(tournament);
     return continueEditing ? RedirectToAction("Edit", new { id = tournament.Id }) : RedirectToAction("List");
 }
        public TournamentDetailsModel GetDetailsById(int tournamentId)
        {
            var matches = _tournamentMatchRepository.Table.Where(m => m.Tournament.Id == tournamentId).Select(tm => tm.Match).ToList();

            var players = new List<PlayerModel>();
            var tournamentPlayers = _tournamentPlayerRepository.Table.Where(t => t.Tournament.Id == tournamentId).Select(tp => tp.Player).ToList();
            tournamentPlayers.ForEach((p) =>
            {
                players.Add(Mapper.Map<Player, PlayerModel>(p));
            });

            var details = new TournamentDetailsModel
            {
                GeneralInfo = Mapper.Map<Tournament, TournamentModel>(_tournamentRepository.GetById(tournamentId)),
                PlayedMatches = matches.Where(m => !m.Deleted && MatchIsCompleted(m)).Select(Mapper.Map<Match, MatchModel>).ToList(),
                PlannedMatches = matches.Where(m => !m.Deleted && !MatchIsCompleted(m)).Select(Mapper.Map<Match, MatchModel>).ToList(),
                Players = players
            };

            return details;
        }