public async Task <IActionResult> Edit(int id, [Bind("Id,ActorId,MovieId")] MovieCastAssignment movieCastAssignment)
        {
            if (id != movieCastAssignment.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(movieCastAssignment);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MovieCastAssignmentExists(movieCastAssignment.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ActorId"] = new SelectList(_context.Actor, "Id", "Id", movieCastAssignment.ActorId);
            ViewData["MovieId"] = new SelectList(_context.Movie, "Id", "Id", movieCastAssignment.MovieId);
            return(View(movieCastAssignment));
        }
        public async Task <IActionResult> Create([Bind("Id,ActorId,MovieId")] MovieCastAssignment movieCastAssignment)
        {
            if (ModelState.IsValid)
            {
                _context.Add(movieCastAssignment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ActorId"] = new SelectList(_context.Actor, "Id", "Id", movieCastAssignment.ActorId);
            ViewData["MovieId"] = new SelectList(_context.Movie, "Id", "Id", movieCastAssignment.MovieId);
            return(View(movieCastAssignment));
        }
Example #3
0
        //gets the movie cast using a lamda query.
        public IActionResult OnGet(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            MovieCastAssignment = _context.MovieCastAssignment
                                  .Include(m => m.Actor)
                                  .Include(m => m.Movie).FirstOrDefault(m => m.Id == id);

            if (MovieCastAssignment == null)
            {
                return(NotFound());
            }
            return(Page());
        }
        //Gets the movie cast for update using a lamda query.
        public IActionResult OnGet(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            MovieCastAssignment = _context.MovieCastAssignment
                                  .Include(m => m.Actor)
                                  .Include(m => m.Movie).FirstOrDefault(m => m.Id == id);

            if (MovieCastAssignment == null)
            {
                return(NotFound());
            }
            ViewData["ActorId"] = new SelectList(_context.Actor, "Id", "Name");
            ViewData["MovieId"] = new SelectList(_context.Set <Movie>(), "Id", "Name");
            return(Page());
        }
Example #5
0
        //Deletes the movie cast from the databse. Uses a linq query to
        //select the movie cast
        public IActionResult OnPost(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            MovieCastAssignment = (from moviecasts in _context.MovieCastAssignment
                                   where moviecasts.Id == id
                                   select moviecasts).FirstOrDefault();

            if (MovieCastAssignment != null)
            {
                _context.MovieCastAssignment.Remove(MovieCastAssignment);
                _context.SaveChanges();
            }

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