示例#1
0
 public void Add(Genre genre)
 {
     using (var ctx = new MovieShopContext())
     {
         //Create the queries
         ctx.Genres.Add(genre);
         //Execute the queries
         ctx.SaveChanges();
     }
 }
示例#2
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();

                    }
                }
            }
        }
示例#3
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)
            {

            }
        }