Exemplo n.º 1
0
        public ICommandResult Handle(CreateUserCommand command)
        {
            // Fail Fast Validation
            command.Validate();

            if (command.Invalid)
            {
                return(new GenericCommandResult(false, "Não foi possível criar o usuário!", command.Notifications));
            }

            var valEmail = _userRepository.GetByEmail(command.Email);

            if (valEmail != null)
            {
                return(new GenericCommandResult(false, "Não foi possível criar o usuário, e-mail já existente!", command.Notifications));
            }

            var searchTemperature = _temperature.GetTemperatureCity(command.City);

            if (searchTemperature == null)
            {
                return(new GenericCommandResult(false, "Não foi possível criar o usuário, verifique a cidade!", command.Notifications));
            }

            // Criptografa a Password e Personal Notes
            var cryptUserPersonalNotes = _encryption.Encrypt(command.PersonalNotes);
            var cryptUserPassword      = _encryption.Encrypt(command.Password);

            var user = new User(command.Name, command.Email, cryptUserPassword, command.City, cryptUserPersonalNotes);

            // Salva no banco
            _userRepository.Create(user);

            // Busca musicas para recomendar
            object playList = ReturnPlayListByTemperature(searchTemperature);

            // Transita apenas os dados necessários
            var userDto = new UserDto(user.Id, user.Name, user.Email, user.City, command.PersonalNotes, searchTemperature, playList);

            return(new GenericCommandResult(true, "Usuário criado", userDto));
        }
Exemplo n.º 2
0
        public IEnumerable <UserDto> GetAll()
        {
            var user = _userRepository.GetAll();

            List <UserDto> userDtoList = new List <UserDto>();

            foreach (var item in user)
            {
                var    searchTemperature = _temperature.GetTemperatureCity(item.City);
                object playList          = ReturnPlayListByTemperature(searchTemperature);

                UserDto userDto = new UserDto(item.Id,
                                              item.Name,
                                              item.Email,
                                              item.City,
                                              _encryption.Decrypt(item.PersonalNotes.ToString()),
                                              searchTemperature,
                                              playList);
                userDtoList.Add(userDto);
            }

            return(userDtoList);
        }