public ApplicationResult <UserDto> Create(UserCreationDto userDto)
        {
            var userEdit = UserEdit.Create(userDto.ExternalId, userDto.UserName, userDto.FullName, userDto.Email);

            var brokenRules = userEdit.GetBrokenValidationRules();

            if (!brokenRules.IsValid)
            {
                return new ApplicationResult <UserDto> {
                           Errors = brokenRules.Errors.ToList(), IsSuccessful = false, IsFailure = true
                }
            }
            ;

            userEdit = _userRepository.Create(userEdit);

            if (userDto.Keys.Any())
            {
                foreach (var key in userDto.Keys)
                {
                    var keyEdit = KeyEdit.Create(userEdit, key.Password);

                    _userRepository.CreateKey(userEdit.Id, keyEdit);
                }
            }

            UnitOfWork.Commit();

            return(new ApplicationResult <UserDto>()
            {
                Data = Mapper.Map <UserDto>(userEdit), IsSuccessful = true, IsFailure = false
            });
        }
        public ApplicationResult <KeyDto> CreateKey(Guid userId, KeyCreationDto keyDto)
        {
            var userEdit = _userRepository.Get(userId);

            var passwordEncrypted = _passwordCryptographer.Encrypt(keyDto.Password);

            var keyEdit = KeyEdit.Create(userEdit, passwordEncrypted);

            var brokenRules = keyEdit.GetBrokenValidationRules();

            if (!brokenRules.IsValid)
            {
                return new ApplicationResult <KeyDto>()
                       {
                           Errors = brokenRules.Errors.ToList(), IsFailure = true
                       }
            }
            ;

            userEdit.CreateKey(keyEdit);

            _userRepository.CreateKey(keyEdit.Id, keyEdit);

            UnitOfWork.Commit();

            return(new ApplicationResult <KeyDto>()
            {
                Data = Mapper.Map <KeyDto>(keyEdit), IsSuccessful = true
            });
        }