// To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Attach(Writer).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!WriterExists(Writer.ID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }
示例#2
0
        public async Task <IActionResult> OnPostAsync(int?id, string[]
                                                      selectedCategories)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var movieToUpdate = await _context.Movie
                                .Include(i => i.Writer)
                                .Include(i => i.MovieGenres)
                                .ThenInclude(i => i.Genre)
                                .FirstOrDefaultAsync(s => s.ID == id);

            if (movieToUpdate == null)
            {
                return(NotFound());
            }
            if (await TryUpdateModelAsync <Movie>(
                    movieToUpdate,
                    "Movie",
                    i => i.Title, i => i.Director,
                    i => i.Duration, i => i.ReleaseDate, i => i.Writer, i => i.Image))
            {
                UpdateMovieGenres(_context, selectedCategories, movieToUpdate);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index"));
            }
            //Apelam UpdateBookCategories pentru a aplica informatiile din checkboxuri la entitatea Books care
            //este editata
            UpdateMovieGenres(_context, selectedCategories, movieToUpdate);
            PopulateAssignedGenreData(_context, movieToUpdate);
            return(Page());
        }
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Genre.Add(Genre);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
        // To protect from overposting attacks, enable the specific properties you want to bind to, for
        // more details, see https://aka.ms/RazorPagesCRUD.
        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.Duration, i => i.ReleaseDate, i => i.WriterID, i => i.Image))
            {
                _context.Movie.Add(newMovie);
                await _context.SaveChangesAsync();

                return(RedirectToPage("./Index")); //ma redirecteaza pe
            }
            PopulateAssignedGenreData(_context, newMovie);
            return(Page());

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _context.Movie.Add(Movie);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Writer = await _context.Writer.FindAsync(id);

            if (Writer != null)
            {
                _context.Writer.Remove(Writer);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
示例#6
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Movie = await _context.Movie.FindAsync(id);

            if (Movie != null)
            {
                _context.Movie.Remove(Movie);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }