public List <Movie> GetAll() { using (MoviesDBEntities1 dbContext = new MoviesDBEntities1()) { return(dbContext.Movies.ToList()); } }
public void AddMovie(Movie newMovie) { using (MoviesDBEntities1 dbContext = new MoviesDBEntities1()) { dbContext.Movies.Add(newMovie); } }
public Movie GetById(int id) { using (MoviesDBEntities1 dbContext = new MoviesDBEntities1()) { return(dbContext .Movies.FirstOrDefault(m => m.MovieId == id)); } }
public void Delete(int id) { using (MoviesDBEntities1 dbContext = new MoviesDBEntities1()) { var foundMovie = dbContext.Movies.FirstOrDefault(m => m.MovieId == id); dbContext.Movies.Remove(foundMovie); dbContext.SaveChanges(); } }
public List <Movie> GetMovies(int pageNumber, int numberOfRecords) { using (MoviesDBEntities1 dbContext = new MoviesDBEntities1()) { return(dbContext .Movies.Skip(numberOfRecords * pageNumber) .Take(numberOfRecords) .ToList()); } }
public void Edit(Movie movie) { using (MoviesDBEntities1 dbContext = new MoviesDBEntities1()) { var foundMovie = dbContext.Movies.FirstOrDefault(m => m.MovieId == movie.MovieId); if (foundMovie != null) { foundMovie.Title = movie.Title; foundMovie.ReleaseDate = movie.ReleaseDate; foundMovie.RunningTime = movie.RunningTime; foundMovie.GenreId = movie.GenreId; foundMovie.BoxOffice = movie.BoxOffice; } } }
public List <Movie> Search(string searchString) { using (MoviesDBEntities1 dbContext = new MoviesDBEntities1()) { if (!String.IsNullOrEmpty(searchString)) { return(dbContext .Movies.Where(movie => movie.Title.Contains(searchString)) .ToList()); } else { return(dbContext.Movies .Take(100) .ToList()); } } }