Ejemplo n.º 1
0
        public async Task UpdateGenreAndGames(int removeId, int moveToId)
        {
            using (_ctx = new RetroDbContext(conString))
            {
                var transaction = await _ctx.Database.BeginTransactionAsync();

                try
                {
                    //games to change
                    var games = _ctx.Games.Where(x => x.GenreId == removeId);
                    foreach (var game in games)
                    {
                        game.GenreId = moveToId;
                    }

                    //Genre to keep
                    var genre = _ctx.Genres.FirstOrDefault(x => x.Id == removeId);
                    if (genre != null)
                    {
                        _ctx.Genres.Remove(genre);
                    }

                    _ctx.UpdateRange(games);
                    await _ctx.SaveChangesAsync();

                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw;
                }
            }
        }
Ejemplo n.º 2
0
 public BaseRepo(RetroDbContext retroDbContext)
 {
     _ctx = retroDbContext;
     _ctx.ChangeTracker.AutoDetectChangesEnabled = false;
     _ctx.ChangeTracker.QueryTrackingBehavior    = QueryTrackingBehavior.NoTracking;
     dbSet = retroDbContext.Set <TEntity>();
 }
Ejemplo n.º 3
0
 public InsertUniqueTests()
 {
     if (!_created)
     {
         using (_ctx = new RetroDbContext(conString))
         {
             _ctx.Database.EnsureCreated();
             _created = true;
         }
     }
 }
Ejemplo n.º 4
0
 public UnitOfWork(string connstring)
 {
     _ctx       = new RetroDbContext(connstring);
     _constring = connstring;
 }