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

            PopulateStaticData(model);

            return View(model);
        }
        public ActionResult Create(PenaltyViewModel model)
        {
            if (ModelState.IsValid)
            {
                model.Penalty.League = leagueService.Get(model.LeagueId);
                model.Penalty.Team = teamService.Get(model.TeamId);

                penaltyService.Save(model.Penalty);
                penaltyService.Commit(); // Seems to have to be committed before updating points/stats

                UpdateTeamLeaguePenaltiesAndStats(model.LeagueId, model.TeamId);

                penaltyService.Commit();

                SuccessMessage(FormMessages.SaveSuccess);

                return RedirectToAction("Index");
            }

            PopulateStaticData(model);

            return View(model);
        }
        public ActionResult Edit(PenaltyViewModel model)
        {
            if (ModelState.IsValid)
            {
                Penalty penaltyToUpdate = penaltyService.Get(model.Penalty.Id);
                TryUpdateModel(penaltyToUpdate, "Penalty");

                penaltyToUpdate.League = leagueService.Get(model.LeagueId);
                penaltyToUpdate.Team = teamService.Get(model.TeamId);

                penaltyService.Save(penaltyToUpdate);

                UpdateTeamLeaguePenaltiesAndStats(model.LeagueId, model.TeamId);

                penaltyService.Commit();

                SuccessMessage(FormMessages.SaveSuccess);

                return RedirectToAction("Index");
            }

            PopulateStaticData(model);

            return View(model);
        }
 private void PopulateStaticData(PenaltyViewModel model)
 {
     model.Teams = teamService.GetTeamsForCurrentSeason().ToSelectList(x => x.ToString(), x => x.Id.ToString(), model.TeamId.ToString());
     model.Leagues = leagueService.Get(orderBy: q => q.OrderByDescending(s => s.Id)).ToSelectList(x => x.Season.ToString() + " " + x.ToString(), x => x.Id.ToString(), model.LeagueId.ToString());
 }
        public ActionResult Edit(int id)
        {
            PenaltyViewModel model = new PenaltyViewModel();
            model.MapToModel(penaltyService.Get(id));

            PopulateStaticData(model);

            return View(model);
        }