Пример #1
0
        public ActionResult AssignConsole(MembershipAssignConsoleViewModel membershipAssignConsoleViewModel)
        {
            if (!ModelState.IsValid)
            {
                RetrieveGamingConsolesAndPutItInViewBag(membershipAssignConsoleViewModel.Game.BranchName);
                return View(membershipAssignConsoleViewModel);
            }

            var membership = membershipRepository.FindByMembershipId(membershipAssignConsoleViewModel.Membership.MembershipId);

            if (membershipAssignConsoleViewModel.Game.HoursPlayed > membership.RemainingHours)
            {
                RetrieveGamingConsolesAndPutItInViewBag(membershipAssignConsoleViewModel.Game.BranchName);
                ModelState.AddModelError("Game", string.Format("Membership has only {0} hours. Please recharge!", membership.RemainingHours));
                return View(membershipAssignConsoleViewModel);
            }

            gameService.AssignConsoleForMembership(membership, membershipAssignConsoleViewModel.Game);
            TempData["Message"] = "Game assigned to membership successfully";
            return RedirectToAction("Index", "Game");
        }
 public void SetUp()
 {
     membershipAssignConsoleViewModel = new MembershipAssignConsoleViewModel { Game = { BranchName = CustomUserIdentity.BranchName } };
 }