public IActionResult StartRequest(TradeRequestViewModel model) { //Creates a new ViewModel for the two Pokemon... FinalTradeRequestViewModel passedModel = new FinalTradeRequestViewModel() { DesiredPokemonId = model.DesiredPokemonId, OfferedPokemonId = model.OfferedPokemonId, isDesiredOwned = model.isDesiredOwned }; //...and sends it to our FinalizeRequest method, which will open a new page ofr the user to finalize their request return(RedirectToAction("FinalizeRequest", passedModel)); }
//Runs when the user is bout to finalize their TradeRequest. Fetches both Pokemon associated, and asks the user to add a comment to their request public async Task <IActionResult> FinalizeRequest(FinalTradeRequestViewModel passedModel) { TradeRequestViewModel model = new TradeRequestViewModel() { DesiredPokemonId = passedModel.DesiredPokemonId, OfferedPokemonId = passedModel.OfferedPokemonId, isDesiredOwned = passedModel.isDesiredOwned }; ApplicationUser currentUser = await GetCurrentUserAsync(); //Fetches the Pokemon the user is requesting model.DesiredPokemon = await _context.CaughtPokemon .Include(cp => cp.Pokemon) .Include(cp => cp.Gender) .Include(cp => cp.User) .Where(cp => cp.User.Id != currentUser.Id) .Where(cp => cp.isOwned == true) .Where(cp => cp.isHidden == false) .Where(cp => cp.isTradeOpen == true) .FirstOrDefaultAsync(cp => cp.Id == passedModel.DesiredPokemonId); if (model.DesiredPokemon == null) { return(NotFound()); } //Fetches the Pokemon the user is offering in return model.OfferedPokemon = await _context.CaughtPokemon .Include(cp => cp.Pokemon) .Include(cp => cp.Gender) .Include(cp => cp.User) .Where(cp => cp.User.Id == currentUser.Id) .Where(cp => cp.isOwned == true) .Where(cp => cp.isHidden == false) .Where(cp => cp.isTradeOpen == true) .FirstOrDefaultAsync(cp => cp.Id == passedModel.OfferedPokemonId); if (model.OfferedPokemon == null) { return(NotFound()); } //Returns these two Pokemon to our View return(View(model)); }