Exemplo n.º 1
0
        public async Task <CommandResult> Handle(ChangeSettingsCommand request, CancellationToken cancellationToken)
        {
            Profile profile = await _profileRepository.GetByIdAsync(request.ProfileId);

            if (!FoundValidProfile(profile))
            {
                return(FailureDueToProfileNotFound());
            }

            ProfileSettings settings = new ProfileSettings(request.PrivacyType);

            profile.ChangeSettings(settings);

            await _profileRepository.UpdateAsync(profile);

            return(await CommitAndPublishDefaultAsync());
        }
        /// <summary>
        /// Cahnges the settigns for a user
        /// </summary>
        /// <param name="changeSettingsCommand"></param>
        /// <returns></returns>
        public ChangeSettingsResponse ChangeSettings(ChangeSettingsCommand changeSettingsCommand)
        {
            if (changeSettingsCommand != null)
            {
                SecurityKeysPair securityKeysPair = _securityKeysRepository.GetByApiKey(changeSettingsCommand.ApiKey);
                if (securityKeysPair != null)
                {
                    User user = _userRepository.GetUserById(securityKeysPair.UserId);

                    if (user != null)
                    {
                        user.ChangeSettings(changeSettingsCommand.Email, changeSettingsCommand.PgpPublicKey,
                                            changeSettingsCommand.Language, changeSettingsCommand.TimeZone,
                                            changeSettingsCommand.IsDefaultAutoLogout,
                                            changeSettingsCommand.AutoLogoutMinutes);

                        _persistenceRepository.SaveUpdate(user);
                        return(new ChangeSettingsResponse(true, "Change Successful"));
                    }
                    else
                    {
                        throw new InstanceNotFoundException(string.Format("{0} {1}",
                                                                          "No User found for the given SecurityKeysPair: ",
                                                                          changeSettingsCommand.ApiKey));
                    }
                }
                else
                {
                    throw new InstanceNotFoundException("No SecurityKeysPair instance found for the given API key");
                }
            }
            else
            {
                throw new NullReferenceException("Given ChangeSettingsCommand is null.");
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> ChangeSettingsAsync(Guid id, [FromBody] ChangeSettingsCommand command)
        {
            command.ProfileId = id;

            return(await CreateCommandResponse(command));
        }