public ActionResult Create([Bind(Include = "genreId,genreName")] genre genre) { if (ModelState.IsValid) { db.genres.Add(genre); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(genre)); }
public IActionResult Create([FromBody] Genre genre) { if (genre == null) { return(BadRequest()); } _context.Genres.Add(genre); _context.SaveChanges(); return(CreatedAtRoute("GetGenres", new { id = genre.ID, }, genre)); }
public GenreController(GenreContext context) { _context = context; if (_context.Genres.Count() == 0) { _context.Genres.Add(new Genre { Name = "fantasy" }); _context.SaveChanges(); } }