//insert public virtual async Task Insert(List <SignalBounce <long> > items) { List <SignalBounceLong> mappedList = items .Select(_mapper.Map <SignalBounceLong>) .ToList(); using (Repository repository = new Repository(_dbContextFactory.GetDbContext())) { InsertCommand <SignalBounceLong> command = repository.Insert <SignalBounceLong>(); command.Insert.ExcludeProperty(x => x.SignalBounceId); int changes = await command.ExecuteAsync(mappedList).ConfigureAwait(false); } }
//insert public virtual async Task Insert(List <SubscriberTopicSettingsLong> items) { using (Repository repository = new Repository(_dbContextFactory.GetDbContext())) { InsertCommand <SubscriberTopicSettingsLong> command = repository.Insert <SubscriberTopicSettingsLong>(); command.Insert.ExcludeProperty(x => x.SubscriberTopicSettingsId); int changes = await command.ExecuteAsync(items) .ConfigureAwait(false); } }
//select public virtual async Task <List <Subscriber <long> > > Select( SubscriptionParameters parameters, SubscribersRangeParameters <long> subscribersRange) { List <Subscriber <long> > subscribers = null; using (var context = _dbContextFactory.GetDbContext()) { IQueryable <Subscriber <long> > query = CreateSelectQuery(parameters, subscribersRange, context); subscribers = await query.ToListAsync().ConfigureAwait(false); } return(subscribers); }
//insert public virtual async Task Insert(List <SubscriberScheduleSettings <long> > periods) { foreach (SubscriberScheduleSettings <long> item in periods) { item.PeriodBegin = SqlDataFomatting.ToSqlTime(item.PeriodBegin); item.PeriodEnd = SqlDataFomatting.ToSqlTime(item.PeriodEnd); } List <SubscriberScheduleSettingsLong> periodsMapped = periods .Select(_mapper.Map <SubscriberScheduleSettingsLong>) .ToList(); using (Repository repository = new Repository(_dbContextFactory.GetDbContext())) { InsertCommand <SubscriberScheduleSettingsLong> command = repository.Insert <SubscriberScheduleSettingsLong>(); command.Insert.ExcludeProperty(x => x.SubscriberScheduleSettingsId); int changes = await command.ExecuteAsync(periodsMapped).ConfigureAwait(false); } }
private static void InitDatabase(IContainer container) { bool dbExists = false; ISenderDbContextFactory contextFactory = container.Resolve <ISenderDbContextFactory>(); using (SenderDbContext context = contextFactory.GetDbContext()) { var creator = (SqlServerDatabaseCreator)context.Database.GetService <IDatabaseCreator>(); dbExists = creator.Exists(); } if (dbExists) { return; } contextFactory.InitializeDatabase(); var deliveryTypeQueries = container.Resolve <ISubscriberDeliveryTypeSettingsQueries <SubscriberDeliveryTypeSettingsLong, long> >(); deliveryTypeQueries.Insert(new List <SubscriberDeliveryTypeSettingsLong> { new SubscriberDeliveryTypeSettingsLong { SubscriberId = 1, DeliveryType = (int)Model.DeliveryTypes.Email, Address = "*****@*****.**", IsEnabled = true } }).Wait(); var categoryQueries = container.Resolve <ISubscriberCategorySettingsQueries <SubscriberCategorySettings <long>, long> >(); categoryQueries.Insert(new List <SubscriberCategorySettings <long> > { new SubscriberCategorySettings <long> { SubscriberId = 1, DeliveryType = (int)Model.DeliveryTypes.Email, CategoryId = (int)CategoryTypes.CustomerGreetings, IsEnabled = true } }).Wait(); }
//methods public override void SpecInit(INeedDbContext instance) { dynamic specsDynamic = instance; AutoMockedContainer autoMockContainer = specsDynamic.Mocker.MoqAutoMocker.Container; string connectionString = @"Data Source=.\;Initial Catalog=SanatanaNotificationsSpecs;integrated security=true;MultipleActiveResultSets=True;"; var connection = new SqlConnectionSettings { ConnectionString = connectionString, Schema = "dbo" }; autoMockContainer.Configure(cfg => { cfg.For <SqlConnectionSettings>().Use(connection); cfg.For <ISenderDbContextFactory>().Use <SenderDbContextFactory>(); cfg.For <INotificationsMapperFactory>().Use <NotificationsMapperFactory>(); cfg.For <IDispatchTemplateQueries <long> >().Use <SqlDispatchTemplateQueries>(); cfg.For <SqlDispatchTemplateQueries>().Use <SqlDispatchTemplateQueries>(); cfg.For <SqlEventSettingsQueries>().Use <SqlEventSettingsQueries>(); cfg.For <SqlSignalBounceQueries>().Use <SqlSignalBounceQueries>(); cfg.For <SqlSignalDispatchQueries>().Use <SqlSignalDispatchQueries>(); cfg.For <SqlSignalEventQueries>().Use <SqlSignalEventQueries>(); cfg.For <SqlStoredNotificationQueries>().Use <SqlStoredNotificationQueries>(); cfg.For <SqlSubscriberCategorySettingsQueries>().Use <SqlSubscriberCategorySettingsQueries>(); cfg.For <SqlSubscriberDeliveryTypeSettingsQueries>().Use <SqlSubscriberDeliveryTypeSettingsQueries>(); cfg.For <SqlSubscriberQueries>().Use <SqlSubscriberQueries>(); cfg.For <SqlSubscriberScheduleSettingsQueries>().Use <SqlSubscriberScheduleSettingsQueries>(); cfg.For <SqlSubscriberTopicSettingsQueries>().Use <SqlSubscriberTopicSettingsQueries>(); }); ISenderDbContextFactory factory = autoMockContainer.GetInstance <ISenderDbContextFactory>(); instance.DbContext = factory.GetDbContext(); instance.DbContext.ChangeTracker.QueryTrackingBehavior = Microsoft.EntityFrameworkCore.QueryTrackingBehavior.NoTracking; }
//insert public virtual async Task Insert(List <EventSettings <long> > items) { List <EventSettingsLong> mappedList = items .Select(_mapper.Map <EventSettingsLong>) .ToList(); using (Repository repository = new Repository(_dbContextFactory.GetDbContext())) using (IDbContextTransaction ts = repository.Context.Database.BeginTransaction()) { SqlTransaction underlyingTransaction = (SqlTransaction)ts.GetDbTransaction(); MergeCommand <EventSettingsLong> mergeCommand = repository.Merge(mappedList, underlyingTransaction); mergeCommand.Insert .ExcludeProperty(x => x.EventSettingsId) .ExcludeProperty(x => x.TemplatesNavigation); mergeCommand.Output .IncludeProperty(x => x.EventSettingsId); int changes = await mergeCommand.ExecuteAsync(MergeType.Insert).ConfigureAwait(false); for (int i = 0; i < mappedList.Count; i++) { EventSettingsLong mappedItem = mappedList[i]; items[i].EventSettingsId = mappedItem.EventSettingsId; if (mappedItem.Templates != null) { mappedItem.Templates.ForEach( x => x.EventSettingsId = mappedItem.EventSettingsId); } } List <DispatchTemplate <long> > templates = items .SelectMany(x => x.Templates) .ToList(); await InsertTemplates(templates, repository.Context, underlyingTransaction) .ConfigureAwait(false); ts.Commit(); } }
//insert public virtual async Task Insert(List <DispatchTemplate <long> > items) { List <DispatchTemplateLong> mappedList = items .Select(_mapper.Map <DispatchTemplateLong>) .ToList(); using (Repository repository = new Repository(_dbContextFactory.GetDbContext())) { InsertCommand <DispatchTemplateLong> insertCommand = repository.Insert <DispatchTemplateLong>(); insertCommand.Insert .ExcludeProperty(x => x.DispatchTemplateId); insertCommand.Output .IncludeProperty(x => x.DispatchTemplateId); int changes = await insertCommand.ExecuteAsync(mappedList).ConfigureAwait(false); for (int i = 0; i < mappedList.Count; i++) { items[i].DispatchTemplateId = mappedList[i].DispatchTemplateId; } } }