Created
January 18, 2022 10:29
-
-
Save emilybache/1e84df0b4d71f612e0759d3aefc30f08 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void changeEmail(String newEmail) | |
{ | |
Object[] data = Database.getUserById(userId); | |
email = (String)data[1]; | |
userType = (UserType)data[2]; | |
if (Objects.equals(email, newEmail)) | |
return; | |
Object[] companyData = Database.getCompany(userId); | |
int companyId = (int)companyData[0]; | |
String companyDomainName = (String)companyData[1]; | |
int numberOfEmployees = (int)companyData[2]; | |
String emailDomain = newEmail.split("@")[1]; | |
boolean isEmailCorporate = Objects.equals(emailDomain, companyDomainName); | |
UserType newType = isEmailCorporate | |
? UserType.Employee | |
: UserType.Customer; | |
if (userType != newType) | |
{ | |
int delta = newType == UserType.Employee ? 1 : -1; | |
int newNumber = numberOfEmployees + delta; | |
Database.saveCompany(companyId, companyDomainName, newNumber); | |
} | |
email = newEmail; | |
userType = newType; | |
Database.saveUser(this); | |
MessageBus.sendEmailChangedMessage(this.userId, newEmail); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment