public ActionResult Create([Bind(Include = "genreId,genreName")] genre genre)
        {
            if (ModelState.IsValid)
            {
                db.genres.Add(genre);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(genre));
        }
Example #2
0
        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));
        }
Example #3
0
        public GenreController(GenreContext context)
        {
            _context = context;

            if (_context.Genres.Count() == 0)
            {
                _context.Genres.Add(new Genre {
                    Name = "fantasy"
                });
                _context.SaveChanges();
            }
        }