public async Task <IActionResult> Edit(int id, [Bind("Id,IdMovie,IdListNavigationId")] MoviesInLists moviesInLists) { if (id != moviesInLists.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(moviesInLists); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MoviesInListsExists(moviesInLists.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["IdListNavigationId"] = new SelectList(_context.Set <Lists>(), "Id", "Id", moviesInLists.IdListNavigationId); return(View(moviesInLists)); }
public async Task <IActionResult> Create([Bind("Id,IdMovie,IdListNavigationId")] MoviesInLists moviesInLists) { if (ModelState.IsValid) { _context.Add(moviesInLists); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["IdListNavigationId"] = new SelectList(_context.Set <Lists>(), "Id", "Id", moviesInLists.IdListNavigationId); return(View(moviesInLists)); }
public async Task <IActionResult> AddMovie(int id) { System.Diagnostics.Debug.WriteLine("ID: " + id); var userId = User.FindFirstValue(ClaimTypes.NameIdentifier); var listIds = await _context.Lists.Where(x => x.OwnerId.Equals(userId)).Select(x => x.Id).ToListAsync(); MoviesInLists movie = new MoviesInLists(); movie.IdMovie = id; movie.IdListNavigationId = listIds.First(); _context.MoviesInLists.Add(movie); _context.SaveChanges(); return(Redirect("~/MyList")); }
public async Task <IActionResult> DeleteMovie(int id) { System.Diagnostics.Debug.WriteLine("ID: " + id); var userId = User.FindFirstValue(ClaimTypes.NameIdentifier); var listIds = await _context.Lists.Where(x => x.OwnerId.Equals(userId)).Select(x => x.Id).ToListAsync(); MoviesInLists movie = new MoviesInLists(); movie.IdMovie = id; movie.IdListNavigationId = listIds.First(); // var entity = _context.MoviesInLists.Attach(movie); var movieId = await _context.MoviesInLists.Where(c => c.IdMovie == id && c.IdListNavigationId == listIds.First()).Select(c => c.Id).ToListAsync(); //var finded = _context.MoviesInLists.Find(movie); movie.Id = movieId.First(); System.Diagnostics.Debug.WriteLine("Finded ID: " + movie.Id); _context.MoviesInLists.Remove(movie); //entity.State = EntityState.Deleted; await _context.SaveChangesAsync(); return(Redirect("~/MyList")); }