protected RelationalConnection([NotNull] DbContextService <IDbContextOptions> options, [NotNull] ILoggerFactory loggerFactory)
            : base(loggerFactory)
        {
            Check.NotNull(options, "options");

            var storeConfig = RelationalOptionsExtension.Extract(options.Service);

            if (storeConfig.Connection != null)
            {
                if (!string.IsNullOrWhiteSpace(storeConfig.ConnectionString))
                {
                    throw new InvalidOperationException(Strings.ConnectionAndConnectionString);
                }

                _connection      = new LazyRef <DbConnection>(() => storeConfig.Connection);
                _connectionOwned = false;
                _openedCount     = storeConfig.Connection.State == ConnectionState.Open ? 1 : 0;
            }
            else if (!string.IsNullOrWhiteSpace(storeConfig.ConnectionString))
            {
                _connectionString = storeConfig.ConnectionString;
                _connection       = new LazyRef <DbConnection>(CreateDbConnection);
                _connectionOwned  = true;
            }
            else
            {
                throw new InvalidOperationException(Strings.NoConnectionOrConnectionString);
            }
        }
        public async Task TestSaveChangesAsync()
        {
            var saveAction = new SampleSaveAction();
            var context    = new SampleDbContext();
            var service    = new DbContextService <SampleDbContext>(context, new List <ISaveAction> {
                saveAction
            });

            Assert.AreEqual(0, saveAction.BeforeSaveChangesCount);
            Assert.AreEqual(0, saveAction.AfterSaveChangesCount);
            Assert.AreEqual(0, saveAction.BeforeSaveChangesCountAsync);
            Assert.AreEqual(0, saveAction.AfterSaveChangesCountAsync);
            Assert.IsFalse(context.SaveChangesCalled);
            Assert.IsFalse(context.SaveChangesAsyncCalled);

            await service.SaveChangesAsync();

            Assert.AreEqual(0, saveAction.BeforeSaveChangesCount);
            Assert.AreEqual(0, saveAction.AfterSaveChangesCount);
            Assert.AreEqual(1, saveAction.BeforeSaveChangesCountAsync);
            Assert.AreEqual(1, saveAction.AfterSaveChangesCountAsync);
            Assert.IsFalse(context.SaveChangesCalled);
            Assert.IsTrue(context.SaveChangesAsyncCalled);
            Assert.IsTrue(context == saveAction.GivenContext);
        }
        public async Task <IActionResult> Firm([FromRoute] string culture)
        {
            FırmViewModel firmViewModel = null;

            try
            {
                // StaticData staticData = await lawyerDbContext.StaticDatas?.SingleOrDefaultAsync();

                int?languageId = DbContextService.GetLanguageIdByShortName(lawyerDbContext, culture);

                if (languageId == null)
                {
                    return(NotFound());
                }

                var firm = (await lawyerDbContext.GetFirmViewAsync()).SingleOrDefault(m => m.LanguageId == languageId);

                firmViewModel = new FırmViewModel
                {
                    Title       = firm?.Title,
                    Description = firm?.Description,
                    Img         = firm?.Img
                };
            }
            catch
            {
                return(NotFound());
            }

            return(View(firmViewModel));
        }
        public async Task <IActionResult> Index([FromRoute] string culture)
        {
            IndexViewModel indexViewModel = null;

            try
            {
                int?languageId = DbContextService.GetLanguageIdByShortName(lawyerDbContext, culture);

                if (languageId == null)
                {
                    return(NotFound());
                }

                indexViewModel = new IndexViewModel
                {
                    Sliders = await lawyerDbContext.Sliders.ToListAsync(),

                    Areas = (await lawyerDbContext.GetAreaViewAsync())
                            .Where(m => m.LanguageId == languageId)
                            .ToList(),

                    Contact = (await lawyerDbContext.GetContactViewAsync())
                              .SingleOrDefault(m => m.LanguageId == languageId),

                    TeamService = (await lawyerDbContext.GetTeamServicesViewAsync())
                                  .SingleOrDefault(m => m.LanguageId == languageId)
                };
            }
            catch
            {
                return(NotFound());
            }

            return(View(indexViewModel));
        }
Example #5
0
        public InMemoryDataStore(
            [NotNull] StateManager stateManager,
            [NotNull] DbContextService <IModel> model,
            [NotNull] EntityKeyFactorySource entityKeyFactorySource,
            [NotNull] EntityMaterializerSource entityMaterializerSource,
            [NotNull] ClrCollectionAccessorSource collectionAccessorSource,
            [NotNull] ClrPropertySetterSource propertySetterSource,
            [NotNull] InMemoryDatabase persistentDatabase,
            [NotNull] DbContextService <IDbContextOptions> options,
            [NotNull] ILoggerFactory loggerFactory)
            : base(stateManager, model, entityKeyFactorySource, entityMaterializerSource,
                   collectionAccessorSource, propertySetterSource, loggerFactory)
        {
            Check.NotNull(persistentDatabase, "persistentDatabase");

            var storeConfig = options.Service.Extensions
                              .OfType <InMemoryOptionsExtension>()
                              .FirstOrDefault();

            _persist = (storeConfig != null ? (bool?)storeConfig.Persist : null) ?? true;

            _database = new ThreadSafeLazyRef <InMemoryDatabase>(
                () => _persist
                    ? persistentDatabase
                    : new InMemoryDatabase(loggerFactory));
        }
        public async Task <IActionResult> Contact([FromRoute] string culture)
        {
            int?languageId = DbContextService.GetLanguageIdByShortName(lawyerDbContext, culture);

            if (languageId == null)
            {
                return(NotFound());
            }

            try
            {
                var contact = (await lawyerDbContext.GetContactViewAsync()).SingleOrDefault(m => m.LanguageId == languageId);

                ContactsViewModel contactsViewModel = new ContactsViewModel
                {
                    Email   = contact?.ContactEmail,
                    Number  = contact?.ContactNumber,
                    Address = contact?.ContactAdress
                };

                return(View(contactsViewModel));
            }
            catch
            {
                return(NotFound());
            }
        }
Example #7
0
        public virtual async Task <object> NextAsync(
            IProperty property,
            DbContextService <DataStoreServices> dataStoreServices,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            Check.NotNull(property, "property");
            Check.NotNull(dataStoreServices, "dataStoreServices");

            var newValue = GetNextValue();

            // If the chosen value is outside of the current block then we need a new block.
            // It is possible that other threads will use all of the new block before this thread
            // gets a chance to use the new new value, so use a while here to do it all again.
            while (newValue.Current >= newValue.Max)
            {
                // Once inside the lock check to see if another thread already got a new block, in which
                // case just get a value out of the new block instead of requesting one.
                using (await _lock.LockAsync(cancellationToken).WithCurrentCulture())
                {
                    if (newValue.Max == _currentValue.Max)
                    {
                        var newCurrent = await GetNewCurrentValueAsync(property, dataStoreServices, cancellationToken);

                        newValue      = new SequenceValue(newCurrent, newCurrent + BlockSize);
                        _currentValue = newValue;
                    }
                    else
                    {
                        newValue = GetNextValue();
                    }
                }
            }

            return(Convert.ChangeType(newValue.Current, property.PropertyType.UnwrapNullableType()));
        }
        public async Task <IActionResult> Index()
        {
            int?languageId = DbContextService.GetLanguageIdByShortName(lawyerDbContext);
            IEnumerable <TeamMemberDto> teamMemberViews = await lawyerDbContext.GetTeamMembersViewAsync();

            return(View(teamMemberViews.Where(m => m.LanguageId == languageId)));
        }
Example #9
0
        public async Task <IActionResult> Index()
        {
            IEnumerable <ContactDto> ContatViews = (await lawyerDbContext.GetContactViewAsync())
                                                   .Where(m => m.LanguageId == DbContextService.GetLanguageIdByShortName(lawyerDbContext));

            return(View(ContatViews));
        }
        public async Task <IActionResult> Details([Required][FromRoute] int id)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    TeamMemberDetailModel teamMembeDetailModel = new TeamMemberDetailModel();

                    teamMembeDetailModel.TeamMemberViews = (await lawyerDbContext.GetTeamMembersViewAsync())
                                                           .Where(m => m.Id == id)
                                                           ?.OrderBy(m => m.LanguageId);
                    teamMembeDetailModel.Languages = await lawyerDbContext.Languages
                                                     .AsNoTracking()
                                                     .ToListAsync();

                    string areaNameKey = lawyerDbContext.TeamToAreas.Include <TeamToArea>("Area")
                                         .FirstOrDefault(m => m.TeamMemberId == id)
                                         ?.Area.NameKey;

                    teamMembeDetailModel.Area = lawyerDbContext.Texts
                                                .SingleOrDefault(m => m.Key == areaNameKey &&
                                                                 m.LanguageId == DbContextService.GetLanguageIdByShortName(lawyerDbContext, "en-US"))
                                                ?.TextContent;

                    return(View(teamMembeDetailModel));
                }
                catch { }
            }
            return(RedirectToAction(nameof(Index)));
        }
Example #11
0
 public ConsoleAdaptor(IValidate validator)
 {
     Validator  = validator;
     User       = new User();
     _dbContext = new DbContextService();
     //StartOperation();
 }
Example #12
0
 public SqlServerBatchExecutor(
     [NotNull] SqlServerTypeMapper typeMapper,
     [NotNull] DbContextService <DbContext> context,
     [NotNull] ILoggerFactory loggerFactory)
     : base(typeMapper, context, loggerFactory)
 {
 }
Example #13
0
        public virtual GeneratedValue Next(IProperty property, DbContextService <DataStoreServices> dataStoreServices)
        {
            Check.NotNull(property, "property");
            Check.NotNull(dataStoreServices, "dataStoreServices");

            var newValue = GetNextValue();

            // If the chosen value is outside of the current block then we need a new block.
            // It is possible that other threads will use all of the new block before this thread
            // gets a chance to use the new new value, so use a while here to do it all again.
            while (newValue.Current >= newValue.Max)
            {
                using (_lock.Lock())
                {
                    // Once inside the lock check to see if another thread already got a new block, in which
                    // case just get a value out of the new block instead of requesting one.
                    if (newValue.Max == _currentValue.Max)
                    {
                        var newCurrent = GetNewCurrentValue(property, dataStoreServices);
                        newValue      = new SequenceValue(newCurrent, newCurrent + _blockSize);
                        _currentValue = newValue;
                    }
                    else
                    {
                        newValue = GetNextValue();
                    }
                }
            }

            return(new GeneratedValue(Convert.ChangeType(newValue.Current, property.PropertyType.UnwrapNullableType())));
        }
Example #14
0
        protected RelationalDataStore(
            [NotNull] StateManager stateManager,
            [NotNull] DbContextService <IModel> model,
            [NotNull] EntityKeyFactorySource entityKeyFactorySource,
            [NotNull] EntityMaterializerSource entityMaterializerSource,
            [NotNull] ClrCollectionAccessorSource collectionAccessorSource,
            [NotNull] ClrPropertySetterSource propertySetterSource,
            [NotNull] RelationalConnection connection,
            [NotNull] CommandBatchPreparer batchPreparer,
            [NotNull] BatchExecutor batchExecutor,
            [NotNull] DbContextService <IDbContextOptions> options,
            [NotNull] ILoggerFactory loggerFactory)
            : base(stateManager, model, entityKeyFactorySource, entityMaterializerSource,
                   collectionAccessorSource, propertySetterSource, loggerFactory)
        {
            Check.NotNull(connection, "connection");
            Check.NotNull(batchPreparer, "batchPreparer");
            Check.NotNull(batchExecutor, "batchExecutor");
            Check.NotNull(options, "options");

            _batchPreparer = batchPreparer;
            _batchExecutor = batchExecutor;
            _connection    = connection;
            _options       = options.Service;
        }
Example #15
0
        public Migrator(
            [NotNull] HistoryRepository historyRepository,
            [NotNull] MigrationAssembly migrationAssembly,
            [NotNull] ModelDiffer modelDiffer,
            [NotNull] IMigrationOperationSqlGeneratorFactory ddlSqlGeneratorFactory,
            [NotNull] SqlGenerator dmlSqlGenerator,
            [NotNull] SqlStatementExecutor sqlExecutor,
            [NotNull] RelationalDataStoreCreator storeCreator,
            [NotNull] RelationalConnection connection,
            [NotNull] ILoggerFactory loggerFactory)
        {
            Check.NotNull(historyRepository, "historyRepository");
            Check.NotNull(migrationAssembly, "migrationAssembly");
            Check.NotNull(modelDiffer, "modelDiffer");
            Check.NotNull(ddlSqlGeneratorFactory, "ddlSqlGeneratorFactory");
            Check.NotNull(dmlSqlGenerator, "dmlSqlGenerator");
            Check.NotNull(sqlExecutor, "sqlExecutor");
            Check.NotNull(storeCreator, "storeCreator");
            Check.NotNull(connection, "connection");
            Check.NotNull(loggerFactory, "loggerFactory");

            _historyRepository      = historyRepository;
            _migrationAssembly      = migrationAssembly;
            _modelDiffer            = modelDiffer;
            _ddlSqlGeneratorFactory = ddlSqlGeneratorFactory;
            _dmlSqlGenerator        = dmlSqlGenerator;
            _sqlExecutor            = sqlExecutor;
            _storeCreator           = storeCreator;
            _connection             = connection;
            _logger = new DbContextService <ILogger>(loggerFactory.Create <Migrator>);
        }
        public async Task <IActionResult> Index()
        {
            IEnumerable <FirmDto> firmViews = (await lawyerDbContext.GetFirmViewAsync())
                                              .Where(m => m.LanguageId == DbContextService.GetLanguageIdByShortName(lawyerDbContext)).ToList();

            return(View(firmViews));
        }
        public StateManager(
            [NotNull] StateEntryFactory factory,
            [NotNull] EntityKeyFactorySource entityKeyFactorySource,
            [NotNull] StateEntrySubscriber subscriber,
            [NotNull] StateEntryNotifier notifier,
            [NotNull] ValueGenerationManager valueGeneration,
            [NotNull] DbContextService <IModel> model,
            [NotNull] DbContextService <DataStore> dataStore)
        {
            Check.NotNull(factory, "factory");
            Check.NotNull(entityKeyFactorySource, "entityKeyFactorySource");
            Check.NotNull(subscriber, "subscriber");
            Check.NotNull(notifier, "notifier");
            Check.NotNull(model, "model");
            Check.NotNull(dataStore, "dataStore");
            Check.NotNull(valueGeneration, "valueGeneration");

            _keyFactorySource = entityKeyFactorySource;
            _factory          = factory;
            _subscriber       = subscriber;
            _notifier         = notifier;
            _valueGeneration  = valueGeneration;
            _model            = model;
            _dataStore        = dataStore;
        }
Example #18
0
        protected DataStore(
            [NotNull] StateManager stateManager,
            [NotNull] DbContextService <IModel> model,
            [NotNull] EntityKeyFactorySource entityKeyFactorySource,
            [NotNull] EntityMaterializerSource entityMaterializerSource,
            [NotNull] ClrCollectionAccessorSource collectionAccessorSource,
            [NotNull] ClrPropertySetterSource propertySetterSource,
            [NotNull] ILoggerFactory loggerFactory)
        {
            Check.NotNull(stateManager, "stateManager");
            Check.NotNull(model, "model");
            Check.NotNull(entityKeyFactorySource, "entityKeyFactorySource");
            Check.NotNull(entityMaterializerSource, "entityMaterializerSource");
            Check.NotNull(collectionAccessorSource, "collectionAccessorSource");
            Check.NotNull(propertySetterSource, "propertySetterSource");
            Check.NotNull(loggerFactory, "loggerFactory");

            _stateManager             = stateManager;
            _model                    = model;
            _entityKeyFactorySource   = entityKeyFactorySource;
            _entityMaterializerSource = entityMaterializerSource;
            _collectionAccessorSource = collectionAccessorSource;
            _propertySetterSource     = propertySetterSource;
            _logger                   = new LazyRef <ILogger>(loggerFactory.Create <DataStore>);
        }
        public MigrationAssembly([NotNull] DbContextService <DbContext> context, [NotNull] DbContextService <IDbContextOptions> options)
        {
            Check.NotNull(context, "context");
            Check.NotNull(options, "options");

            _context = context;
            _options = options;
        }
Example #20
0
        protected DataStoreSource([NotNull] DbContextServices services, [NotNull] DbContextService <IDbContextOptions> options)
        {
            Check.NotNull(services, "services");
            Check.NotNull(options, "options");

            _services = services;
            _options  = options;
        }
Example #21
0
 public InMemoryDatabaseFacade(
     [NotNull] DbContextService <IModel> model,
     [NotNull] InMemoryDataStoreCreator dataStoreCreator,
     [NotNull] InMemoryConnection connection,
     [NotNull] ILoggerFactory loggerFactory)
     : base(model, dataStoreCreator, connection, loggerFactory)
 {
 }
Example #22
0
 protected RelationalDatabase(
     [NotNull] DbContextService <IModel> model,
     [NotNull] DataStoreCreator dataStoreCreator,
     [NotNull] DataStoreConnection connection,
     [NotNull] ILoggerFactory loggerFactory)
     : base(model, dataStoreCreator, connection, loggerFactory)
 {
 }
Example #23
0
 public ConcreteDatabase(
     DbContextService <IModel> model,
     DataStoreCreator dataStoreCreator,
     DataStoreConnection connection,
     ILoggerFactory loggerFactory)
     : base(model, dataStoreCreator, connection, loggerFactory)
 {
 }
        public async Task TestSaveChangesAsync_NoActions()
        {
            var context = new SampleDbContext();
            var service = new DbContextService <SampleDbContext>(context);
            await service.SaveChangesAsync();

            Assert.IsFalse(context.SaveChangesCalled);
            Assert.IsTrue(context.SaveChangesAsyncCalled);
        }
Example #25
0
        public virtual Task <GeneratedValue> NextAsync(
            IProperty property,
            DbContextService <DataStoreServices> dataStoreServices,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            Check.NotNull(property, "property");

            return(Task.FromResult(Next(property)));
        }
Example #26
0
 /// <inheritdoc>
 public virtual TModel Find(object[] key)
 {
     using (var ctx = DbContextService.CreateContext())
     {
         var dbSet  = ctx.Set(typeof(TEntity));
         var entity = dbSet.Find(key);
         if (entity == null)
         {
             return(default);
 public SqlServerDatabase(
     [NotNull] DbContextService <IModel> model,
     [NotNull] SqlServerDataStoreCreator dataStoreCreator,
     [NotNull] SqlServerConnection connection,
     [NotNull] SqlServerMigrator migrator,
     [NotNull] ILoggerFactory loggerFactory)
     : base(model, dataStoreCreator, connection, migrator, loggerFactory)
 {
 }
        public void TestSaveChanges_NoActions()
        {
            var context = new SampleDbContext();
            var service = new DbContextService <SampleDbContext>(context);

            service.SaveChanges();
            Assert.IsTrue(context.SaveChangesCalled);
            Assert.IsFalse(context.SaveChangesAsyncCalled);
        }
Example #29
0
 public ConcreteMigrationsEnabledDatabase(
     DbContextService <IModel> model,
     DataStoreCreator dataStoreCreator,
     DataStoreConnection connection,
     Migrator migrator,
     ILoggerFactory loggerFactory)
     : base(model, dataStoreCreator, connection, migrator, loggerFactory)
 {
 }
Example #30
0
 public FakeDatabase(
     DbContextService <IModel> model,
     RecordingDataStoreCreator dataStoreCreator,
     FakeRelationalConnection connection,
     TestMigrator migrator,
     ILoggerFactory loggerFactory)
     : base(model, dataStoreCreator, connection, migrator, loggerFactory)
 {
 }