public async Task CreateAsync(string email, string password, string SettingsHost, int SettingsPort) { var emailAccount = await _emailAccountRepository.GetByEmailAsync(email); var settings = await _settingsRepository.GetAsyncByPort(SettingsPort); if (emailAccount != null) { throw new Exception($"Client with E-Mail: '{email}' already exsist."); } if (settings == null) { settings = new Smtp(SettingsPort, SettingsHost); } emailAccount = new EmailAccount(email, password); await _emailAccountRepository.AddAsync(emailAccount); }
public async Task CreateAsync(User user, string email, string password, string settingsHost, int settingsPort) { if (!await EmailAccountValuesValidator.EmailAccountUsingImapIsValid(settingsHost, settingsPort, email, password)) { throw new Exception("Invalid imap email account's credentials"); } var emailAccount = new EmailAccount(email, password); emailAccount.AddUser(user); var imap = await _imapRepository.GetAsyncByPort(settingsPort); if (imap != null) { emailAccount.AddImapSettings(imap); } else { emailAccount.AddImapSettings(new Imap(settingsPort, settingsHost)); } await _emailAccountRepository.AddAsync(emailAccount); }