public async Task BulkUploadApprenticeshipEvents(IList <ApprenticeshipEvent> apprenticeshipEvents) { _logger.Debug($"Bulk uploading {apprenticeshipEvents.Count} apprenticeship events"); var sw = Stopwatch.StartNew(); var table = BuildApprenticeshipEventsDataTable(apprenticeshipEvents); var priceTable = BuildPriceHistoryDataTable(apprenticeshipEvents); _logger.Trace($"Building events and price history data table took {sw.ElapsedMilliseconds}"); sw = Stopwatch.StartNew(); await WithConnection(async con => { await con.ExecuteAsync( "[dbo].[CreateApprenticeshipEventsV2]", param: new { @events = table.AsTableValuedParameter("[dbo].[ApprenticeshipEventsTypeV2]"), @priceHistory = priceTable.AsTableValuedParameter("[dbo].[PriceHistoryType]") }, commandType: CommandType.StoredProcedure); return(1L); }); _logger.Trace($"Inserting events in to database took {sw.ElapsedMilliseconds}"); }
protected override async Task HandleCore(BulkUploadCreateApprenticeshipEventsCommand command) { var validationResult = _validator.Validate(command); if (!validationResult.IsValid) { throw new ValidationException(validationResult.Errors); } var sw = Stopwatch.StartNew(); SetCreatedDate(command.ApprenticeshipEvents); _logger.Trace($"Setting created date took {sw.ElapsedMilliseconds}"); await _apprenticeshipEventRepository.BulkUploadApprenticeshipEvents(command.ApprenticeshipEvents); }