//update public virtual async Task RewriteSets(long subscriberId, List <SubscriberScheduleSettings <long> > periods) { foreach (SubscriberScheduleSettings <long> item in periods) { item.PeriodBegin = SqlDataFomatting.ToSqlTime(item.PeriodBegin); item.PeriodEnd = SqlDataFomatting.ToSqlTime(item.PeriodEnd); } List <int> sets = periods .Select(x => x.Set) .Distinct() .ToList(); List <SubscriberScheduleSettingsLong> periodsMapped = periods .Select(_mapper.Map <SubscriberScheduleSettingsLong>) .ToList(); using (var repository = new Repository(_dbContextFactory.GetDbContext())) using (IDbContextTransaction ts = repository.Context.Database.BeginTransaction()) { SqlTransaction underlyingTransaction = (SqlTransaction)ts.GetDbTransaction(); int changes = await repository.DeleteManyAsync <SubscriberScheduleSettingsLong>( x => x.SubscriberId == subscriberId && sets.Contains(x.Set)) .ConfigureAwait(false); InsertCommand <SubscriberScheduleSettingsLong> insertCommand = repository .Insert <SubscriberScheduleSettingsLong>(underlyingTransaction); insertCommand.Insert .ExcludeProperty(x => x.SubscriberScheduleSettingsId); changes = await insertCommand.ExecuteAsync(periodsMapped).ConfigureAwait(false); ts.Commit(); } }
//insert public virtual async Task Insert(List <SubscriberCategorySettingsLong> items) { using (Repository repository = new Repository(_dbContextFactory.GetDbContext())) { InsertCommand <SubscriberCategorySettingsLong> command = repository.Insert <SubscriberCategorySettingsLong>(); command.Insert.ExcludeProperty(x => x.SubscriberCategorySettingsId); int changes = await command.ExecuteAsync(items).ConfigureAwait(false); } }
//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 <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); } }
//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; } } }