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)); }