public ActionResult UpdateKeeperSettings(KeeperSettingsModel model)
        {
            if (!ModelState.IsValid)
            {
                throw new ArgumentException("Invalid KeeperSettingsModel detected.");
            }

            using (var session = _sessionFactory.OpenSession())
            {
                var leagueData = session.Get<LeagueDao>(model.LeagueKey) ?? new LeagueDao() { Key = model.LeagueKey };

                using (var transaction = session.BeginTransaction())
                {
                    leagueData.AllowKeepersFromPriorSeason = model.AllowKeepersFromPriorSeason;
                    session.SaveOrUpdate(leagueData);
                    transaction.Commit();
                }
            }

            TempData["UserSuccessMessage"] = "Keeper settings successfully saved.";
            return RedirectToAction("ListTeams", new { leagueKey = model.LeagueKey });
        }
 public void UpdateKeeperSettings_LeagueKeyEmpty_Redirects()
 {
     var model = new KeeperSettingsModel();
     _leagueController.ModelState.AddModelError("Key", "Error Message");
     RedirectToRouteResult result = _leagueController.UpdateKeeperSettings(model) as RedirectToRouteResult;
 }
        public void UpdateKeeperSettings_LeagueDataExists_Succeeds()
        {
            const string leagueKey = "1.l.2";

            var model = new KeeperSettingsModel() { LeagueKey = leagueKey, AllowKeepersFromPriorSeason = false };

            // Setup query expectations
            var leagueData = new LeagueDao() { Key = leagueKey, AllowKeepersFromPriorSeason = true };
            ISession mockSession = MockRepository.GenerateMock<ISession>();
            _mockSessionFactory.Expect(f => f.OpenSession()).Return(mockSession);
            mockSession.Expect(s => s.Get<LeagueDao>(leagueKey)).Return(leagueData);

            // Setup save expectation
            ITransaction mockTransaction = MockRepository.GenerateMock<ITransaction>();
            mockSession.Expect(s => s.BeginTransaction()).Return(mockTransaction);
            mockSession.Expect(s => s.SaveOrUpdate(Arg<LeagueDao>.Matches(l => l.AllowKeepersFromPriorSeason == false && l.Key == leagueKey)));
            mockTransaction.Expect(t => t.Commit());

            // Act
            RedirectToRouteResult result = _leagueController.UpdateKeeperSettings(model) as RedirectToRouteResult;

            // Verify
            Assert.IsNotNull(result, "Expected redirect result.");
            result.AssertActionRedirect().ToAction("ListTeams").WithParameter("leagueKey", leagueKey);
            _mockSessionFactory.VerifyAllExpectations();
            mockSession.VerifyAllExpectations();
        }
        public ActionResult ViewKeeperSettings(string leagueKey)
        {
            KeeperSettingsModel model;

            using (var session = _sessionFactory.OpenSession())
            {
                var leagueData = session.Get<LeagueDao>(leagueKey);

                if (leagueData != null)
                {
                    model = new KeeperSettingsModel(leagueData);
                }
                else
                {
                    model = new KeeperSettingsModel() { LeagueKey = leagueKey };
                }
            }

            return View(model);
        }