コード例 #1
0
 // returns all items from the table "Studios" table in the database
 public List <Studio> GetAll()
 {
     using (studioContext = new MovieStudioContext())
     {
         return(studioContext.Studios.ToList());
     }
 }
コード例 #2
0
 // 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));
     }
 }
コード例 #3
0
 // 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));
     }
 }
コード例 #4
0
 // returns all items from the table "Movies" table in the database
 public List <Movie> GetAll()
 {
     using (movieContext = new MovieStudioContext())
     {
         return(movieContext.Movies.ToList());
     }
 }
コード例 #5
0
 // 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();
     }
 }
コード例 #6
0
 // 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();
     }
 }
コード例 #7
0
 // 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();
         }
     }
 }
コード例 #8
0
 // 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();
         }
     }
 }
コード例 #9
0
 // 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();
         }
     }
 }
コード例 #10
0
 // 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();
         }
     }
 }