Пример #1
0
        public async Task <IActionResult> OnPostAsync(string[] selectedCategories)
        {
            var newMovie = new Movie(); if (selectedCategories != null)

            {
                newMovie.MovieGenres = new List <MovieGenre>(); foreach (var cat in selectedCategories)
                {
                    var catToAdd = new MovieGenre
                    {
                        GenreID = int.Parse(cat)
                    }; newMovie.MovieGenres.Add(catToAdd);
                }
            }
            if (await TryUpdateModelAsync <Movie>(newMovie, "Movie", i => i.Title, i => i.Director, i => i.Price, i => i.ProductionDate, i => i.ProducerID))
            {
                _context.Movie.Add(newMovie); await _context.SaveChangesAsync(); return(RedirectToPage("./Index"));
            }
            PopulateAssignedCategoryData(_context, newMovie); return(Page());
        }