public static List<Genre> GetForMovie(int id) { using (MovieEntities context = new MovieEntities()) { return context.Movies.Where(x => x.ID == id).First().Genres.ToList(); } }
public static Genre GetByID(int id) { using (MovieEntities context = new MovieEntities()) { return context.Genres.Where(x => x.ID == id).First(); } }
public static List<Genre> GetAll() { using (MovieEntities context = new MovieEntities()) { return context.Genres.OrderBy(x => x.Name).ToList(); } }
public static Movie GetByID(int id) { using (MovieEntities context = new MovieEntities()) { var movie = context.Movies.Include(x => x.Genres).Where(x => x.ID == id).First(); return movie; } }
public static List<Movie> GetAll() { using (MovieEntities context = new MovieEntities()) { var movies = context.Movies.Include(x => x.Genres).OrderBy(x => x.Title).ToList(); return movies; } }
public static void Delete(int id) { using (MovieEntities context = new MovieEntities()) { var movie = context.Movies.Where(x => x.ID == id).First(); context.Movies.Remove(movie); context.SaveChanges(); } }
public static void Edit(int id, string title, DateTime releaseDate, decimal price, List<int> genres) { using (MovieEntities context = new MovieEntities()) { var movie = context.Movies.Where(x => x.ID == id).First(); movie.Title = title; movie.ReleaseDate = releaseDate; movie.Genres.Clear(); foreach (var genreID in genres) { var genre = context.Genres.Find(genreID); movie.Genres.Add(genre); } context.SaveChanges(); } }
public static void Add(string title, DateTime releaseDate, int runningTime, List<int> genres) { using (MovieEntities context = new MovieEntities()) { var movie = new Movie() { Title = title, ReleaseDate = releaseDate, RunningTime = runningTime }; foreach (var genreID in genres) { var genre = context.Genres.Find(genreID); movie.Genres.Add(genre); } context.Movies.Add(movie); context.SaveChanges(); } }