Esempio n. 1
0
 public List<Genre> ReadAll()
 {
     using (var ctx = new MovieShopContext())
     {
         return ctx.Genres.ToList();
     }
 }
Esempio n. 2
0
 public void Add(Genre genre)
 {
     using (var ctx = new MovieShopContext())
     {
         //Create the queries
         ctx.Genres.Add(genre);
         //Execute the queries
         ctx.SaveChanges();
     }
 }
Esempio n. 3
0
        public void Update(Genre genre)
        {
            using (var ctx = new MovieShopContext())
            {
                foreach (var movieDB in ctx.Genres.ToList())
                {
                    if (genre.Id == movieDB.Id)
                    {
                        movieDB.Name = genre.Name;
                        ctx.SaveChanges();

                    }
                }
            }
        }
Esempio n. 4
0
        public void Delete(int genreId)
        {
            Genre genre = FindGenre(genreId);
            try
            {
                using (var ctx = new MovieShopContext())
                {
                    ctx.Genres.Attach(genre);
                    ctx.Genres.Remove(genre);
                    ctx.SaveChanges();
                }
            }
            catch (DbUpdateConcurrencyException)
            {

            }
        }