예제 #1
0
        public IActionResult Edit(ShelfModificationViewModel model)
        {
            var currentUserId = GetCurrentUserId().Result;

            if (!ModelState.IsValid)
            {
                return(Edit());
            }
            foreach (var gameId in model.IdsToAdd)
            {
                var gameAppUser = new GameAppUser {
                    UserId = currentUserId, GameId = gameId
                };
                _shelfRepository.AddToShelf(gameAppUser);
            }

            foreach (var gameId in model.IdsToDelete)
            {
                var gameAppUser = new GameAppUser {
                    UserId = currentUserId, GameId = gameId
                };
                _shelfRepository.RemoveFromShelf(gameAppUser);
            }

            TempData["SuccessMessage"] = Constants.GeneralSuccessMessage;
            return(RedirectToAction(nameof(List)));
        }
        public IActionResult Edit(int id)
        {
            var currentUserId = GetCurrentUserId().Result;

            var gameAppUser = new GameAppUser {
                UserId = currentUserId, GameId = id
            };

            _shelfRepository.AddToShelf(gameAppUser);

            TempData["SuccessMessage"] = Constants.GeneralSuccessMessage;
            return(RedirectToAction(nameof(Edit)));
        }