示例#1
0
        public async Task <bool> DoWork(User user, UserLoginLog userLoginLog)
        {
            await _transactionalExecutor.ExecuteAsync <bool>(async connection =>
            {
                _userRepository.SetSqlExecutorForTransaction(connection);
                _userLoginLogRepository.SetSqlExecutorForTransaction(connection);

                await _userRepository.Update(user.Id, user);
                await _userLoginLogRepository.Insert(user.Id, userLoginLog);

                return(true);
            });

            return(true);
        }
示例#2
0
        public async Task <(bool, Organization, User)> DoWork(Organization organization, User user, UserLoginLog userLoginLog,
                                                              Integration integration, IntegrationClient integrationClient, Project project)
        {
            var(organizationResult,
                userResult) = await _transactionalExecutor.ExecuteAsync(async connection =>
            {
                _userRepository.SetSqlExecutorForTransaction(connection);
                _organizationRepository.SetSqlExecutorForTransaction(connection);
                _userLoginLogRepository.SetSqlExecutorForTransaction(connection);
                _integrationRepository.SetSqlExecutorForTransaction(connection);
                _integrationClientRepository.SetSqlExecutorForTransaction(connection);
                _projectRepository.SetSqlExecutorForTransaction(connection);

                var organizationId = await _organizationRepository.Insert(0, organization);
                organization.Id    = organizationId;

                user.OrganizationId = organizationId;
                var userId          = await _userRepository.Insert(0, user);
                user.Id             = userId;

                userLoginLog.OrganizationId = organizationId;
                userLoginLog.UserId         = userId;
                await _userLoginLogRepository.Insert(userId, userLoginLog);

                organization.CreatedBy = userId;
                organization.UserCount++;
                user.CreatedBy = userId;
                await _organizationRepository.Update(userId, organization);
                await _userRepository.Update(userId, user);

                integration.OrganizationId = organizationId;
                var integrationId          = await _integrationRepository.Insert(userId, integration);

                integrationClient.OrganizationId = organizationId;
                integrationClient.IntegrationId  = integrationId;
                await _integrationClientRepository.Insert(userId, integrationClient);

                project.OrganizationId = organizationId;
                var projectId          = await _projectRepository.Insert(userId, project);

                if (!organization.IsSuperOrganization)
                {
                    var superProject = await _projectRepository.Select(x => x.IsSuperProject);
                    if (superProject.IsExist())
                    {
                        var labels            = await _labelRepository.SelectAll(x => x.ProjectId == superProject.Id);
                        var labelTranslations = await _labelTranslationRepository.SelectAll(x => x.ProjectId == superProject.Id);

                        for (var i = 0; i < labels.Count; i++)
                        {
                            var label              = labels[i];
                            label.Uid              = Guid.NewGuid();
                            label.OrganizationId   = project.OrganizationId;
                            label.OrganizationUid  = project.OrganizationUid;
                            label.OrganizationName = project.OrganizationName;
                            label.ProjectId        = projectId;
                            label.ProjectUid       = project.Uid;
                            label.ProjectName      = project.Name;

                            var labelId = await _labelRepository.Insert(userId, label);

                            var labelsTranslations = labelTranslations.Where(x => x.LabelName == label.Name).ToList();
                            for (var j = 0; j < labelsTranslations.Count; j++)
                            {
                                var labelTranslation              = labelsTranslations[j];
                                labelTranslation.Uid              = Guid.NewGuid();
                                labelTranslation.OrganizationId   = project.OrganizationId;
                                labelTranslation.OrganizationUid  = project.OrganizationUid;
                                labelTranslation.OrganizationName = project.OrganizationName;
                                labelTranslation.ProjectId        = projectId;
                                labelTranslation.ProjectUid       = project.Uid;
                                labelTranslation.ProjectName      = project.Name;
                                labelTranslation.LabelId          = labelId;
                                labelTranslation.LabelUid         = label.Uid;
                                labelTranslation.LabelName        = label.Name;

                                await _labelTranslationRepository.Insert(userId, labelTranslation);
                            }
                        }
                    }
                }

                return(organization,
                       user);
            });

            return(true,
                   organizationResult,
                   userResult);
        }