public async Task <IActionResult> Create(MovieGenreCreateViewModel model)
 {
     if (ModelState.IsValid)
     {
         context.Add(new Genre()
         {
             Naam = model.Naam, MovieID = model.MovieID
         });
         await context.SaveChangesAsync();
     }
     ViewData["MovieID"] = new SelectList(context.Movies, "ID", "Titel", model.MovieID);
     return(RedirectToAction(nameof(Index)));
 }
Example #2
0
        public IActionResult Create(MovieGenreCreateViewModel model)
        {
            if (!TryValidateModel(model))
            {
                return(RedirectToAction("Index"));
            }
            MovieGenre movieGenreToCreate = new MovieGenre {
                Naam = model.Naam
            };

            _movieGenreService.Insert(movieGenreToCreate);

            return(RedirectToAction("Index"));
        }
        public IActionResult Create(MovieGenreCreateViewModel model)
        {
            if (!TryValidateModel(model))
            {
                return(View(model));
            }

            foreach (var genre in _context.MovieGenres)
            {
                if (model.Name == genre.Name)
                {
                    return(View());
                }
            }

            var movieGenre = new MovieGenre()
            {
                Name = model.Name
            };

            _context.InsertMovieGenre(movieGenre);

            return(RedirectToAction("Index"));
        }