Esempio n. 1
0
        public async Task <ActionResult <GamesGenres> > PostGamesGenres(GamesGenres gamesGenres)
        {
            _context.GamesGenres.Add(gamesGenres);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetGamesGenres", new { id = gamesGenres.GamesGenresId }, gamesGenres));
        }
Esempio n. 2
0
        public async Task <IActionResult> PutGamesGenres(int id, GamesGenres gamesGenres)
        {
            if (id != gamesGenres.GamesGenresId)
            {
                return(BadRequest());
            }

            _context.Entry(gamesGenres).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GamesGenresExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,GameId,GenreId")] GamesGenres gamesGenres)
        {
            if (id != gamesGenres.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(gamesGenres);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!GamesGenresExists(gamesGenres.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["GameId"]  = new SelectList(_context.ComputerGames, "Id", "Engine", gamesGenres.GameId);
            ViewData["GenreId"] = new SelectList(_context.Genres, "Id", "Info", gamesGenres.GenreId);
            return(View(gamesGenres));
        }
        public async Task <IActionResult> Create(int GameId, [Bind("Id,GenreId")] GamesGenres gamesGenres)
        {
            gamesGenres.GameId = GameId;
            if (ModelState.IsValid)
            {
                _context.Add(gamesGenres);
                await _context.SaveChangesAsync();

                //return RedirectToAction(nameof(Index));
                return(RedirectToAction("Index", "GamesGenres", new { id = GameId, name = _context.ComputerGames.Where(c => c.Id == GameId).FirstOrDefault().Name }));
            }
            //ViewData["GameId"] = new SelectList(_context.ComputerGames, "Id", "Name", gamesGenres.GameId);
            //ViewData["GenreId"] = new SelectList(_context.Genres, "Id", "Name", gamesGenres.GenreId);
            //return View(gamesGenres);
            return(RedirectToAction("Index", "GamesGenres", new { id = GameId, name = _context.ComputerGames.Where(c => c.Id == GameId).FirstOrDefault().Name }));
        }