Beispiel #1
0
        public async Task ExecuteAsync(SetupCofoundryCommand command, IExecutionContext executionContext)
        {
            var settings = await _domainRepository.ExecuteQueryAsync(new GetSettingsQuery <InternalSettings>());

            if (settings.IsSetup)
            {
                throw new InvalidOperationException("Site is already set up.");
            }

            using (var scope = _domainRepository.Transactions().CreateScope())
            {
                var userId = await CreateAdminUser(command);

                var settingsCommand = await _domainRepository.ExecuteQueryAsync(new GetPatchableCommandQuery <UpdateGeneralSiteSettingsCommand>());

                settingsCommand.ApplicationName = command.ApplicationName;
                await _domainRepository.ExecuteCommandAsync(settingsCommand);

                // Take the opportunity to break the cache in case any additional install scripts have been run since initialization
                _objectCacheFactory.Clear();

                // Setup Complete
                await _domainRepository.ExecuteCommandAsync(new MarkAsSetUpCommand());

                await scope.CompleteAsync();
            }
        }
        public async Task <int> NextNumber(string sequenceName)
        {
            var command = new GenerateNextNumberCommand {
                CounterName = sequenceName
            };
            await DomainRepository.ExecuteCommandAsync(command);

            return(command.OutputValue);
        }
Beispiel #3
0
        /// <summary>
        /// Patches a command to modify the current state and then executes it.
        /// </summary>
        /// <typeparam name="TCommand">Type of command to patch and execute.</typeparam>
        /// <param name="id">
        /// The integer database identifier of the entity associated with
        /// patchable command.
        /// </param>
        /// <param name="commandPatcher">
        /// An action to configure or "patch" a command that's been initialized
        /// with existing data.
        /// </param>
        public static async Task PatchCommandAsync <TCommand>(this IDomainRepository repository, int id, Action <TCommand> commandPatcher)
            where TCommand : IPatchableByIdCommand
        {
            var query   = new GetPatchableCommandByIdQuery <TCommand>(id);
            var command = await repository.ExecuteQueryAsync(query);

            commandPatcher(command);

            await repository.ExecuteCommandAsync(command);
        }
Beispiel #4
0
        private async Task AuthenticateAsync(UpdateCurrentUserPasswordCommand command, User user)
        {
            if (_userAuthenticationHelper.VerifyPassword(user, command.OldPassword) == PasswordVerificationResult.Failed)
            {
                var logFailedAttemptCommand = new LogFailedAuthenticationAttemptCommand(user.UserAreaCode, user.Username);
                await _domainRepository.ExecuteCommandAsync(logFailedAttemptCommand);

                UserValidationErrors.Authentication.InvalidPassword.Throw(nameof(command.OldPassword));
            }
        }
        public async Task <ActionResult> Index()
        {
            var settings = await _domainRepository.ExecuteQueryAsync(new GetSettingsQuery <InternalSettings>());

            if (settings.IsSetup)
            {
                return(RedirectToDashboard());
            }

            // force sign-out - solves a rare case where you're re-initializing a db after being signed into a previous version.
            await _domainRepository.ExecuteCommandAsync(new SignOutCurrentUserFromAllUserAreasCommand());

            var viewPath = ViewPathFormatter.View("Setup", nameof(Index));

            return(View(viewPath));
        }
Beispiel #6
0
        public async Task ExecuteAsync(DeleteCurrentUserCommand command, IExecutionContext executionContext)
        {
            _permissionValidationService.EnforceIsSignedIn(executionContext.UserContext);
            var userId = executionContext.UserContext.UserId.Value;

            using (var scope = _domainRepository.Transactions().CreateScope())
            {
                await _domainRepository
                .WithElevatedPermissions()
                .ExecuteCommandAsync(new DeleteUserCommand(userId));

                await _domainRepository
                .ExecuteCommandAsync(new SignOutCurrentUserCommand());

                await scope.CompleteAsync();
            }
        }
        public async Task <JsonResult> PatchDraft(int pageId, [FromBody] IDelta <UpdatePageDraftVersionCommand> delta)
        {
            // Custom patching because we may need to create a draft version first
            var query   = new GetPatchableCommandByIdQuery <UpdatePageDraftVersionCommand>(pageId);
            var command = await _domainRepository.ExecuteQueryAsync(query);

            if (command == null)
            {
                var createDraftCommand = new AddPageDraftVersionCommand();
                createDraftCommand.PageId = pageId;
                await _domainRepository.ExecuteCommandAsync(createDraftCommand);

                command = await _domainRepository.ExecuteQueryAsync(query);
            }

            delta.Patch(command);

            return(await _apiResponseHelper.RunCommandAsync(command));
        }
Beispiel #8
0
        public async Task ExecuteAsync(SignInUserWithCredentialsCommand command, IExecutionContext executionContext)
        {
            var authResult = await _domainRepository
                             .WithContext(executionContext)
                             .ExecuteQueryAsync(new AuthenticateUserCredentialsQuery()
            {
                UserAreaCode       = command.UserAreaCode,
                Username           = command.Username,
                Password           = command.Password,
                PropertyToValidate = nameof(command.Password)
            });

            authResult.ThrowIfNotSuccess();

            await _domainRepository.ExecuteCommandAsync(new SignInAuthenticatedUserCommand()
            {
                UserId       = authResult.User.UserId,
                RememberUser = command.RememberUser
            });
        }