public async Task <IActionResult> Edit(int id, [Bind("MovieId,GenreId")] MovieGenres movieGenres) { if (id != movieGenres.MovieId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(movieGenres); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MovieGenresExists(movieGenres.MovieId)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } ViewData["GenreId"] = new SelectList(_context.Genre, "Id", "Id", movieGenres.GenreId); ViewData["MovieId"] = new SelectList(_context.Movie, "Id", "Id", movieGenres.MovieId); return(View(movieGenres)); }
public ActionResult Save(Movie movie) { if (!ModelState.IsValid) { var viewModel = new MovieGenres { Movie = movie, Genres = _context.Genres.ToList() }; return(View("NewMovie", viewModel)); } if (movie.Id == 0) { _context.Movies.Add(movie); } else { var movieInDb = _context.Movies.Single(m => m.Id == movie.Id); movieInDb.DateAdded = movie.DateAdded; movieInDb.GenreId = movie.GenreId; movieInDb.Name = movie.Name; movieInDb.NumberInStock = movie.NumberInStock; movieInDb.ReleaseDate = movie.ReleaseDate; } _context.SaveChanges(); return(RedirectToAction("Random")); }
public ActionResult NewMovie(int id) { MovieGenres newMovieGenres; if (id == 0) { newMovieGenres = new MovieGenres { Genres = _context.Genres.ToList(), } } ; else { var movieInDb = _context.Movies.SingleOrDefault(m => m.Id == id); newMovieGenres = new MovieGenres { Genres = _context.Genres.ToList(), Movie = movieInDb }; } return(View(newMovieGenres)); }
private void Adapt(Models.Genre[] genres, int[] genreIds, out string[] output) { output = new string[0]; List <string> list = new List <string>(); if (genres != null) { list.AddRange(genres .Select(g => g.Name) .Distinct(StringComparer.OrdinalIgnoreCase) .ToArray()); } if (genreIds != null) { list.AddRange(genreIds .Select(id => MovieGenres.Get(id).Name) .Except(new [] { MovieGenres.Unknown.Name }) .Except(list) .Distinct(StringComparer.OrdinalIgnoreCase) .ToArray()); } output = list .ToArray(); }
public void UpdateMovieGenre(int id, MovieGenre updatedMovieGenre) { var movieGenre = MovieGenres.SingleOrDefault(x => x.Id == id); if (movieGenre != null) { movieGenre.Name = updatedMovieGenre.Name; } this.SaveChanges(); }
public void DeleteMovieGenre(int id) { var movieGenre = MovieGenres.SingleOrDefault(x => x.Id == id); if (movieGenre != null) { MovieGenres.Remove(movieGenre); } this.SaveChanges(); }
public async Task <IActionResult> Create([Bind("MovieId,GenreId")] MovieGenres movieGenres) { if (ModelState.IsValid) { _context.Add(movieGenres); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewData["GenreId"] = new SelectList(_context.Genre, "Id", "Id", movieGenres.GenreId); ViewData["MovieId"] = new SelectList(_context.Movie, "Id", "Id", movieGenres.MovieId); return(View(movieGenres)); }
private void AddGenresOfMovie(ICollection <int> selectedGenresIds, int movieId) { var collectionToAdd = new List <MovieGenres>(); foreach (var genreId in selectedGenresIds.Distinct().ToList()) { //check if genre exists and relation doesn't if (DbContext.Genres.Any(p => p.Id == genreId) && !DbContext.MovieActors.Any(ma => ma.PersonId == genreId && ma.MovieId == movieId)) { var item = new MovieGenres() { GenreId = genreId, MovieId = movieId }; collectionToAdd.Add(item); } } DbContext.MovieGenres.AddRange(collectionToAdd); DbContext.SaveChanges(); }
public async Task Init() { try { if (Year == "") { Year = "0"; } int.Parse(Year); } catch { await Application.Current.MainPage.DisplayAlert("Error", "The year must be a number!", "OK"); return; } if (MovieGenres.Count == 0) { MovieGenres.Add(new Genre { GenreID = 0, Name = "None" }); var serviceReturns = await _genreService.Get <List <Genre> >(null); foreach (var item in serviceReturns) { MovieGenres.Add(item); } } MediaList.Clear(); int GenreID = 0; try { GenreID = SelectedGenre.GenreID; } catch { GenreID = 0; } MediaSearchRequest request = new MediaSearchRequest { GenreID = GenreID, Title = MovieTitle, Year = int.Parse(Year) }; string query = await request.ToQueryString(); var list = await $"{APIService._apiUrl}/MediaSearch?{query}".GetJsonAsync <IEnumerable <Media> >(); foreach (var item in list) { if (item.MediaID != 1) { MediaList.Add(new ListItem { Id = item.MediaID, Title = item.Title, Description = item.Synopsis, Image = $"{APIService._apiUrl}/images/covers/{item.MediaID}", Rating = int.Parse(await $"{APIService._apiUrl}/MediaRatings?id={item.MediaID}&username={APIService.Username}".GetStringAsync()) }); } } }
public List <Movie> searchByGenre(MovieGenres genre) { return(this.movieList.FindAll(m => m.Genres.Contains(genre))); }
public MovieGenre InsertMovieGenre(MovieGenre movieGenre) { MovieGenres.Add(movieGenre); this.SaveChanges(); return(movieGenre); }
//--------------------// // MovieGenre methods // //--------------------// public MovieGenre GetMovieGenre(int id) { return(MovieGenres.FirstOrDefault(x => x.Id == id)); }