Example #1
0
 public void BeforeEachTest()
 {
     sessionFactory = new DbContextSessionFactory();
     uow            = new DbUnitOfWork(sessionFactory);
     persister      = new DbSagaPersister(sessionFactory);
     saga           = GetTestSaga();
 }
Example #2
0
 public DbApiTester()
 {
     IdGenerator        = HiLoIdGenerator.DbHiloGIdGenerator(1, 1, 1);
     UnitOfWork         = new DbUnitOfWork(Clock, IdGenerator);
     RoleRepository     = new DbRoleRepository(UnitOfWork);
     AuthUserRepository = new DbAuthUserRepository(RoleRepository, UnitOfWork);
     UserRepository     = new DbUserRepository(UnitOfWork);
     GameRepository     = new DbGameRepository(UnitOfWork);
 }
Example #3
0
        public UserModel GetById(Guid id, bool includeInActive = false, bool includeNonPublic = false)
        {
            using (var uow = new DbUnitOfWork(_context))
            {
                var repositories = new IRepository[] { _repository };

                uow.Enlist(repositories);
                uow.InitTransaction();

                return(Filter(Populate(_repository.GetById(id), includeInActive, includeNonPublic), includeInActive, includeNonPublic));
            }
        }
Example #4
0
        public IEnumerable <UserModel> GetAll(bool includeInActive = false, bool includeNonPublic = false)
        {
            using (var uow = new DbUnitOfWork(_context))
            {
                var repositories = new IRepository[] { _repository };

                uow.Enlist(repositories);
                uow.InitTransaction();

                return(Filter(_repository.GetAll().Select(o => Populate(o, includeInActive, includeNonPublic)), includeInActive, includeNonPublic));
            }
        }
        public async Task Save <TModel, TModelKeyType, TEntity, TEntityKeyType>(TModel model, CancellationToken cancellationToken, EntityState entityState, bool updateModelAfterCommit = false)
            where TModel : class, IKey <TModelKeyType>
            where TModelKeyType : IEquatable <TModelKeyType>
            where TEntity : class, IKey <TEntityKeyType>
            where TEntityKeyType : IEquatable <TEntityKeyType>
        {
            using (IUnitOfWorkScope <TUnitOfWork> scope = UnitOfWorkScopeFactory.Create(UowFactory))
            {
                DbUnitOfWork dbContext = scope.UnitOfWork as DbUnitOfWork;
                if (dbContext == null)
                {
                    throw new InvalidOperationException("Unsupported Unit of Work.");
                }

                dbContext.Entry(model).State = entityState;
                await scope.CommitAsync(cancellationToken);
            }
        }
        public async Task Save <TModel, TModelKeyType, TEntity, TEntityKeyType>(TModel model, CancellationToken cancellationToken, EntityState entityState, bool updateModelAfterCommit = false)
            where TModel : class, IKey <TModelKeyType>
            where TModelKeyType : IEquatable <TModelKeyType>
            where TEntity : class, IKey <TEntityKeyType>
            where TEntityKeyType : IEquatable <TEntityKeyType>
        {
            using (IUnitOfWorkScope <TUnitOfWork> scope = UnitOfWorkScopeFactory.Create(UowFactory))
            {
                DbUnitOfWork dbContext = scope.UnitOfWork as DbUnitOfWork;
                if (dbContext == null)
                {
                    throw new InvalidOperationException("Unsupported Unit of Work.");
                }

                var entityEntry =
                    dbContext.ChangeTracker.Entries <TEntity>()
                    .Where(e => !e.Entity.Id.Equals(default(TEntityKeyType)))
                    .Where(e => typeof(TEntityKeyType) == typeof(TModelKeyType) ? e.Entity.Id.Equals(model.Id) : e.Entity.Id.ToString() == model.Id.ToString())
                    .SingleOrDefault();
                if (entityEntry == null)
                {
                    TEntity entity = Mapper.Map <TModel, TEntity>(model);
                    entityEntry = dbContext.Entry(entity);
                }

                entityEntry.State = entityState;
                if (updateModelAfterCommit)
                {
                    switch (entityState)
                    {
                    case EntityState.Added:
                    case EntityState.Modified:
                        dbContext.OnCommit += (db, e) => Mapper.Map(entityEntry.Entity, model);     // Refresh model in case of DB-assigned values (Identity/timestamp/etc.).
                        break;
                    }
                }

                await scope.CommitAsync(cancellationToken);
            }
        }
Example #7
0
 public DebtRepository(DbUnitOfWork unitOfWork)
     : base(unitOfWork)
 {
 }
Example #8
0
 public QuoteRepository(DbUnitOfWork <DevAVDb> unitOfWork) : base(unitOfWork, x => x.Set <Quote>(), x => x.Id)
 {
 }
 public ConfigurationRepository(DbUnitOfWork unitOfWork)
     : base(unitOfWork)
 {
 }
Example #10
0
 public OrderRepository(DbUnitOfWork <DevAVDb> unitOfWork) : base(unitOfWork, x => x.Set <Order>(), x => x.Id)
 {
 }
Example #11
0
 public void SetUp()
 {
     _unitOfWork = new DbUnitOfWork(_connection);
 }
Example #12
0
 public DebtInstallmentRepository(DbUnitOfWork unitOfWork)
     : base(unitOfWork)
 {
 }
 public RepositoryFactory(DbUnitOfWork DbUnitOfWork)
 {
     _dbUnitOfWork = DbUnitOfWork;
 }