public IActionResult Index(ItemsShopViewModel model) { if (model.ItemId != 0 && model.CurrentPlayerId != 0) { _gameService.Buy(model.CurrentPlayerId, model.ItemId); } return(RedirectToAction("Index")); }
public IActionResult Index() { //Get all items, sorted by Price var allItems = _itemService.Find().OrderBy(i => i.Price).ToList(); //Get current logged in player var currentPlayer = _playerService.Find().SingleOrDefault(p => User.Identity != null && p.Name == User.Identity.Name); if (currentPlayer != null) { var model = new ItemsShopViewModel() { AllItems = allItems, CurrentPlayer = currentPlayer, ItemId = 0, CurrentPlayerId = currentPlayer.Id }; return(View(model)); } //need errorhandling instead of redirecting to home return(RedirectToAction("Index", "Home")); }