public async Task <FilmGenreView> GetFilmById(int id) { FilmGenreView fgv = new FilmGenreView(); await Task.Run(() => { fgv.Id = id; fgv.Title = dbc.Films.Where(f => f.Id == id).First().Title; fgv.Description = dbc.Films.Where(f => f.Id == id).First().Description; fgv.Year = dbc.Films.Where(f => f.Id == id).First().Year; fgv.PosterPath = $"/Content/Posters/{dbc.Films.Where(f => f.Id == id).First().PosterPath}"; fgv.PosterBGPath = $"/Content/Posters/{dbc.Films.Where(f => f.Id == id).First().PosterBGPath}"; fgv.Country = dbc.Films.Where(f => f.Id == id).First().Country; var g = from fg in dbc.FilmGenres from film in dbc.Films from genre in dbc.Genres where fg.FilmId == id where fg.GenreId == genre.Id where fg.FilmId == film.Id select genre.Name; foreach (var genre in g) { fgv.Genres.Add(genre); } }); return(fgv); }
public ActionResult AddFilm(FilmGenreView fg) { List <string> genres = new List <string>(); foreach (var gen in fg.Genres) { if (gen != "false") { genres.Add(gen); } } Film film = new Film(); film.Title = fg.Title; film.Description = fg.Description; film.Year = fg.Year; film.PosterPath = fg.PosterPath; film.PosterBGPath = fg.PosterBGPath; film.Country = fg.Country; dbc.Films.Add(film); dbc.SaveChanges(); int filmId = dbc.Films.Where(ff => ff.Title == fg.Title).Select(f => f.Id).First(); foreach (var genre in genres) { dbc.FilmGenres.Add(new FilmGenre() { FilmId = filmId, GenreId = dbc.Genres.Where(gg => gg.Name == genre).Select(g => g.Id).First() }); } dbc.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <ActionResult> Details(int id) { FilmGenreView film = await GetFilmById(id); return(View(film)); }