public ActionResult Create()
        {
            PlayerViewModel model = new PlayerViewModel();

            PopulateStaticData(model);

            return View(model);
        }
        public ActionResult Edit(int id)
        {
            Player player = playerService.Get(id);
            PlayerViewModel model = new PlayerViewModel();
            model.MapToModel(player);

            PopulateStaticData(model);

            return View(model);
        }
        public ActionResult Create(PlayerViewModel model)
        {
            if (ModelState.IsValid)
            {
                if(model.TeamId.HasValue)
                    model.Player.Team = teamService.Get(model.TeamId.Value);

                playerService.Insert(model.Player);
                playerService.Commit();

                SuccessMessage(FormMessages.SaveSuccess);
                return RedirectToAction("Index");
            }

            PopulateStaticData(model);

            return View(model);
        }
        public ActionResult Edit(PlayerViewModel model)
        {
            if (ModelState.IsValid)
            {
                Player playerToUpdate = playerService.Get(model.Player.Id);

                TryUpdateModel(playerToUpdate, "Player");

                playerToUpdate.Team.Touch();
                playerToUpdate.Team = model.TeamId.HasValue ? this.teamService.Get(model.TeamId.Value) : null;

                playerService.Update(playerToUpdate);
                playerService.Commit();

                SuccessMessage(FormMessages.SaveSuccess);
                return RedirectToAction("Index");
            }

            PopulateStaticData(model);

            return View(model);
        }
 private void PopulateStaticData(PlayerViewModel model)
 {
     model.Teams = teamService.GetTeamsForCurrentSeason().ToSelectListWithHeader(x => x.ToString(), x => x.Id.ToString(), model.TeamId.ToString(), "None");
 }