public async Task <CommandResult> GetProfileByIdUser(Guid id) { var profile = await _profileRepository.GetByUserId(id); if (profile == null) { return(new CommandResult(false, "Profile not found.", null)); } var result = new ProfileCommandResponse(profile.Id, profile.Document.Cpf ?? "", profile.Document.Cnpj ?? "", profile.Email.Address, profile.Name.FirstName, profile.Name.LastName, profile.Phone.FixNumber, profile.Phone.MobileNumber, profile.ImageUrl, profile.UserId, profile.Address.Id, profile.Address.Street, profile.Address.City, profile.Address.Country, profile.Address.ZipCode ); return(new CommandResult(true, "Perfil", result)); }
public async Task <CommandResult> Handler(EditProfileCommand command) { if (!command.Validated()) { return(new CommandResult(false, "Error editing profile", command.Notifications)); } var profile = await _profileRepository.GetById(new Guid(command.Id)); var user = await _userRepository.GetUserById(new Guid(command.UserId)); var address = await _addressRepository.GetById(new Guid(command.AddressId)); var email = new Email(command.Email); var name = new Name(command.FirstName, command.LastName); var document = new Document(command.Cpf, command.Cnpj); var phone = new Phone(command.FixPhone, command.MobilePhone); address = address.EditAddress(command.Street, command.City, command.Country, command.ZipCode); await _addressRepository.Update(address); string imageUrl; var image = command.Image; if (image != null && image.Length > 0) { imageUrl = await _uploadService.UploadImageProfile(user.Id, image.OpenReadStream()); } else { imageUrl = profile.ImageUrl; } var profileEdit = profile.EditProfile(name, imageUrl, document, email, phone, user, address); await _profileRepository.Update(profileEdit); var response = new ProfileCommandResponse( profile.Id, profile.Document.Cpf, profile.Document.Cnpj, profile.Email.Address, profile.Name.FirstName, profile.Name.LastName, profile.Phone.FixNumber, profile.Phone.MobileNumber, profile.ImageUrl, profile.User.Id, profile.Address.Id, profile.Address.Street, profile.Address.City, profile.Address.Country, profile.Address.ZipCode ); return(new CommandResult(true, "perfil editado com sucesso", response)); }