Couple fixes for beta.
This commit is contained in:
@@ -240,6 +240,34 @@ public class AccountService : BaseDatabaseService, IAccountService
|
||||
return accounts;
|
||||
}
|
||||
|
||||
public async Task<bool> AccountNameExistsAsync(string name, Guid? excludedAccountId = null)
|
||||
{
|
||||
var normalizedName = name?.Trim();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(normalizedName))
|
||||
return false;
|
||||
|
||||
var accounts = await Connection.Table<MailAccount>().ToListAsync().ConfigureAwait(false);
|
||||
|
||||
return accounts.Any(account =>
|
||||
account.Id != excludedAccountId &&
|
||||
string.Equals(account.Name?.Trim(), normalizedName, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
public async Task<bool> AccountAddressExistsAsync(string address, Guid? excludedAccountId = null)
|
||||
{
|
||||
var normalizedAddress = address?.Trim();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(normalizedAddress))
|
||||
return false;
|
||||
|
||||
var accounts = await Connection.Table<MailAccount>().ToListAsync().ConfigureAwait(false);
|
||||
|
||||
return accounts.Any(account =>
|
||||
account.Id != excludedAccountId &&
|
||||
string.Equals(account.Address?.Trim(), normalizedAddress, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
public async Task CreateRootAliasAsync(Guid accountId, string address)
|
||||
{
|
||||
var rootAlias = new MailAccountAlias()
|
||||
@@ -610,6 +638,12 @@ public class AccountService : BaseDatabaseService, IAccountService
|
||||
{
|
||||
Guard.IsNotNull(account);
|
||||
|
||||
if (await AccountNameExistsAsync(account.Name).ConfigureAwait(false))
|
||||
throw new InvalidOperationException(Translator.DialogMessage_AccountNameExistsMessage);
|
||||
|
||||
if (await AccountAddressExistsAsync(account.Address).ConfigureAwait(false))
|
||||
throw new InvalidOperationException(Translator.DialogMessage_AccountAddressExistsMessage);
|
||||
|
||||
if (!account.CreatedAt.HasValue)
|
||||
{
|
||||
account.CreatedAt = DateTime.UtcNow;
|
||||
|
||||
Reference in New Issue
Block a user