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