Example #1
0
        public ActionResult Add([Bind("HoursPlayed,PersonalScore,GameId,UserListId")] GameList gameList)
        {
            var validate = _gameListService.ValidateGameList(gameList);

            ModelState.Merge(validate);
            gameList.AddedDate = DateTime.Now;

            if (ModelState.IsValid)
            {
                var errors = _gameListService.ValidateGameList(gameList);
                if (!errors.Any())
                {
                    _gameListService.Add(gameList);

                    return(RedirectToAction("Manage"));
                }
                ModelState.Merge(errors);
            }
            ViewBag.userList = _userService.GetUserIdNamesList(null);
            ViewBag.Games    = _gameService.GetAllActive();

            return(View(gameList));
        }
Example #2
0
        public IViewComponentResult Invoke(int?gameid)
        {
            if (!gameid.HasValue)
            {
                gameid = 0;
            }
            var userid    = _userService.GetLoggedInUserId();
            var userLists = _userListService.GetUserUserLists(userid).ToList();

            var gameList = TempData.Get <GameList>("gameList");

            if (TempData["GameListId"] != null)
            {
                var gamelistid = TempData["GameListId"] as int?;
                if (gamelistid.HasValue)
                {
                    gameList.Id = gamelistid.Value;
                }
            }

            if (gameList != null)
            {
                var errors = _gameListService.ValidateGameList(gameList);
                ModelState.Merge(errors);
            }


            if (gameList == null)
            {
                gameList = _gameListService.GetAll().FirstOrDefault(g => g.GameId == gameid && g.UserList.UserId == userid);
            }
            if (gameList == null)
            {
                gameList = new GameList();
            }

            ViewBag.UserListId = userLists;
            ViewBag.GameId     = gameid;
            ViewBag.Id         = gameList.Id;

            return(View("_AddGameToUserList", gameList));
        }
Example #3
0
        public IViewComponentResult Invoke(int userid, int?gamelistid)
        {
            var userLists = _userListService.GetUserUserLists(userid).ToList();

            var gameList = TempData.Get <GameList>("gameList");

            if (gameList != null && gamelistid.HasValue)
            {
                if (gameList.Id != gamelistid)
                {
                    gameList = null;
                }
            }

            if (gameList != null)
            {
                var errors = _gameListService.ValidateGameList(gameList);
                ModelState.Merge(errors);
            }


            if (gameList == null)
            {
                gameList = _gameListService.GetAll().SingleOrDefault(g => g.Id == gamelistid);
            }
            if (gameList == null)
            {
                gameList = new GameList();
            }

            ViewBag.UserListId = userLists;
            ViewBag.Id         = gameList.Id;
            ViewBag.Games      = _gameService.GetAllActive();

            return(View("_UserGameListForm", gameList));
        }