// returns all items from the table "Studios" table in the database public List <Studio> GetAll() { using (studioContext = new MovieStudioContext()) { return(studioContext.Studios.ToList()); } }
// returns the item with a specific id from the table "Studios" table in the database public Studio Get(int id) { using (studioContext = new MovieStudioContext()) { return(studioContext.Studios.Find(id)); } }
// returns the item with a specific id from the table "Movies" table in the database public Movie Get(int id) { using (movieContext = new MovieStudioContext()) { return(movieContext.Movies.Find(id)); } }
// returns all items from the table "Movies" table in the database public List <Movie> GetAll() { using (movieContext = new MovieStudioContext()) { return(movieContext.Movies.ToList()); } }
// adds new item in the "Studios" table in the database public void Add(Studio studio) { using (studioContext = new MovieStudioContext()) { studioContext.Studios.Add(studio); studioContext.SaveChanges(); } }
// adds new item in the "Movies" table in the database public void Add(Movie movie) { using (movieContext = new MovieStudioContext()) { movieContext.Movies.Add(movie); movieContext.SaveChanges(); } }
// deletes item from the database's table "Studios" by given id // if item with thethe given id exists public void Delete(int id) { using (studioContext = new MovieStudioContext()) { var studio = studioContext.Studios.Find(id); if (studio != null) { studioContext.Studios.Remove(studio); studioContext.SaveChanges(); } } }
// updates an item from the database's table "Studios" by given object from the class Studio // if item with the object's id exists public void Update(Studio studio) { using (studioContext = new MovieStudioContext()) { var item = studioContext.Studios.Find(studio.Id); if (item != null) { studioContext.Entry(item).CurrentValues.SetValues(studio); studioContext.SaveChanges(); } } }
// deletes item from the database's table "Movies" by given id // if item with thethe given id exists public void Delete(int id) { using (movieContext = new MovieStudioContext()) { var movie = movieContext.Movies.Find(id); if (movie != null) { movieContext.Movies.Remove(movie); movieContext.SaveChanges(); } } }
// updates an item from the database's table "Movies" by given object from the class Movie // if item with the object's id exists public void Update(Movie movie) { using (movieContext = new MovieStudioContext()) { var item = movieContext.Movies.Find(movie.Id); if (item != null) { movieContext.Entry(item).CurrentValues.SetValues(movie); movieContext.SaveChanges(); } } }