void NormalizeContextForUpdate(FilmsContext context, params Film[] films) { try { context.Configuration.AutoDetectChangesEnabled = false; foreach (var film in films) { var newGenres = new List <Genre>(); newGenres.AddRange(film.Genres); film.Genres.Clear(); context.Films.Attach(film); if (film.FilmId != default(long) && context.Films.Any(f => f.FilmId == film.FilmId)) { context.Entry(film).Collection(f => f.Genres).Load(); context.Entry(film).State = EntityState.Modified; } else { context.Entry(film).State = EntityState.Added; } foreach (var genre in newGenres) { if (!film.Genres.Any(g => g.GenreId == genre.GenreId || g.Name.Equals(genre.Name, StringComparison.CurrentCultureIgnoreCase))) { context.Genres.Attach(genre); film.Genres.Add(genre); if (!context.Genres.Any(g => g.Name.ToUpper() == genre.Name.ToUpper())) { context.Entry(genre).State = EntityState.Added; } } } var counter = 0; while (counter < film.Genres.Count) { var genre = film.Genres[counter]; if (!newGenres.Any(g => g.GenreId == genre.GenreId || g.Name.Equals(genre.Name, StringComparison.CurrentCultureIgnoreCase))) { film.Genres.Remove(genre); } else { counter++; } } } } catch { throw; } finally { context.ChangeTracker.DetectChanges(); context.Configuration.AutoDetectChangesEnabled = true; } }
public async Task CreateFilmAsync(Film film) { using (var context = new FilmsContext()) { context.Films.Add(film); await context.SaveChangesAsync(); } }
public async Task UpdateFilmAsync(Film film) { using (var context = new FilmsContext()) { context.Entry(film).State = EntityState.Modified; await context.SaveChangesAsync(); } }
public async Task <Film[]> ReadFilmsByIndex(int index, int count) { Film[] result; using (var context = new FilmsContext()) { result = await context.Films.OrderBy(f => f.FilmId).Skip(index).Take(count).ToArrayAsync(); } return(result); }
public async Task <Film[]> ReadFilmsByUserAsync(string user) { Film[] result; using (var context = new FilmsContext()) { result = await context.Films.Where(f => f.User == user).ToArrayAsync(); } return(result); }
public async Task DeleteFilmAsync(int Id) { using (var context = new FilmsContext()) { var film = await context.Films.FirstOrDefaultAsync(f => f.FilmId == Id); context.Entry(film).State = EntityState.Deleted; await context.SaveChangesAsync(); } }
public async Task <Film[]> ReadFilmsAsync() { var result = new Film[0]; using (var context = new FilmsContext()) { result = await context.Films.ToArrayAsync(); } return(result); }
public async Task <int> ReadFilmsCountAsync() { var result = 0; using (var context = new FilmsContext()) { result = await context.Films.CountAsync(); } return(result); }
public UnitTest1() { var builder = new DbContextOptionsBuilder <FilmsContext>() .UseSqlServer( "Server=localhost\\SQLEXPRESS; Database=Films;Trusted_Connection=True;" ); context = new FilmsContext(builder.Options); _dataRepository = new CompteManager(context); compteController = new CompteController(_dataRepository); }
public async Task <Film> ReadFilmOrDefaultAsync(int Id) { Film result = null; using (var context = new FilmsContext()) { result = await context.Films.FirstOrDefaultAsync(f => f.FilmId == Id); } return(result); }
public FilmValid(FilmsContext _context, Film film) { this._context = _context; this.film = film; }
public CartManager(FilmsContext db, ISessionManager session) { this.db = db; this.session = session; }
public CountryValid(FilmsContext _context, Country country) { this._context = _context; this.country = country; }
FilmsContext CreateFilmContext() { var res = new FilmsContext(_connectionString); return(res); }
public HomeController(ILogger <HomeController> logger, FilmsContext context) { _logger = logger; _context = context; }
public DirectorsController(FilmsContext context) { _context = context; }
public CompaniesController(FilmsContext context) { _context = context; }
public CompteManager(FilmsContext context) { _filmRatingsDbContext = context; }
public GenresController(FilmsContext context) { _context = context; }
public CountriesController(FilmsContext context) { _context = context; }
public FilmGenreValid(FilmsContext _context, FilmGenre filmgenre) { this._context = _context; this.filmgenre = filmgenre; }
public DirectorValid(FilmsContext _context, Director director) { this._context = _context; this.director = director; }
public CartController() { db = new FilmsContext(); session = new SessionManager(); cartManager = new CartManager(db, session); }
public GenreValid(FilmsContext _context, Genre genre) { this._context = _context; this.genre = genre; }
public CompanyValid(FilmsContext _context, Company company) { this._context = _context; this.company = company; }
public FilmsItemsController(FilmsContext context) { _context = context; }
public ManageController() { _db = new FilmsContext(); }