Exemple #1
0
        protected override async Task <CompleteModel> Process(TopicMultipleUpdateCommand request, CancellationToken cancellationToken)
        {
            if (request.Topics.Count == 0)
            {
                Logger.LogWarning("No topics to process");
                return(new CompleteModel());
            }

            int rows = await _dataSession
                       .MergeData($"[{TopicMap.Table.Schema}].[{TopicMap.Table.Name}]")
                       .IncludeInsert()
                       .IncludeUpdate()
                       .Mode(DataMergeMode.SqlStatement)
                       .Map <TopicMultipleUpdateModel>(m =>
            {
                m.Column(p => p.Id).Key();
                m.Column(p => p.TenantId);
                m.Column(p => p.Title);
                m.Column(p => p.CalendarYear);
                m.Column(p => p.TargetMonth);
                m.Column(p => p.Created);
                m.Column(p => p.CreatedBy);
                m.Column(p => p.Updated);
                m.Column(p => p.UpdatedBy);
            })
                       .ExecuteAsync(request.Topics, cancellationToken);

            Logger.LogInformation("Processed {rows} topics", rows);

            return(new CompleteModel());
        }
        /// <summary>
        /// Import data using the specified <paramref name="importDefinition" /> and <paramref name="importData" />.
        /// </summary>
        /// <param name="importDefinition">The import definition.</param>
        /// <param name="importData">The import data.</param>
        /// <param name="username">The name of the user importing the data.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>The results of the import</returns>
        /// <exception cref="ArgumentNullException"><paramref name="importData" /> or <paramref name="importDefinition" /> is null</exception>
        public virtual async Task <ImportResult> ImportAsync(ImportDefinition importDefinition, ImportData importData, string username, CancellationToken cancellationToken = default)
        {
            if (importData == null)
            {
                throw new ArgumentNullException(nameof(importData));
            }
            if (importDefinition == null)
            {
                throw new ArgumentNullException(nameof(importDefinition));
            }

            var context = new ImportProcessContext(importDefinition, importData, username, _importFactory);

            var dataTable = CreateTable(context);

            await PopulateTable(context, dataTable);

            var mergeDefinition = CreateMergeDefinition(context);

            var result = await _dataSession
                         .MergeData(mergeDefinition)
                         .ExecuteAsync(dataTable, cancellationToken);

            return(new ImportResult {
                Processed = result, Errors = context.Errors
            });
        }
        protected override async Task <CompleteModel> Process(MemberAssignRoleCommand request, CancellationToken cancellationToken)
        {
            if (request.Users.Count == 0 || request.Roles.Count == 0)
            {
                Logger.LogWarning("No users or roles to process");
                return(new CompleteModel());
            }

            var assignments = from user in request.Users
                              from role in request.Roles
                              select new MemberAssignRoleModel
            {
                TenantId = request.TenantId,
                UserName = user,
                RoleName = role
            };

            int rows = await _dataSession
                       .MergeData("[IQ].[TenantUserRole]")
                       .IncludeInsert()
                       .IncludeUpdate(false)
                       .Mode(DataMergeMode.SqlStatement)
                       .Map <MemberAssignRoleModel>(m =>
            {
                m.Column(p => p.TenantId).Key();
                m.Column(p => p.UserName).Key();
                m.Column(p => p.RoleName).Key();
            })
                       .ExecuteAsync(assignments, cancellationToken);

            Logger.LogInformation("Processed {rows} user role assignments", rows);

            return(new CompleteModel());
        }
Exemple #4
0
        private IEnumerable <DataMergeOutputRow> Merge(DataMergeDefinition mergeDefinition, DataTable dataTable)
        {
            _logger.LogDebug("Executing batch merge to: '{table}'", mergeDefinition.TargetTable);

            var result = _dataSession
                         .MergeData(mergeDefinition)
                         .ExecuteOutput(dataTable)
                         .ToList();

            return(result);
        }