Accounts dialog: more user-friendly validation
This commit is contained in:
parent
9a458bf3dc
commit
6e84fd97f1
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net5.0</TargetFramework>
|
<TargetFramework>net5.0</TargetFramework>
|
||||||
<Version>6.4.2.1</Version>
|
<Version>6.4.2.2</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -112,6 +112,9 @@ namespace LibationWinForms.Dialogs
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if (!inputIsValid())
|
||||||
|
return;
|
||||||
|
|
||||||
// without transaction, accounts persister will write ANY EDIT immediately to file
|
// without transaction, accounts persister will write ANY EDIT immediately to file
|
||||||
using var persister = AudibleApiStorage.GetAccountsSettingsPersister();
|
using var persister = AudibleApiStorage.GetAccountsSettingsPersister();
|
||||||
|
|
||||||
@ -129,6 +132,28 @@ namespace LibationWinForms.Dialogs
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool inputIsValid()
|
||||||
|
{
|
||||||
|
var dtos = getRowDtos();
|
||||||
|
|
||||||
|
foreach (var dto in dtos)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(dto.AccountId))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Account id cannot be blank. Please enter an account id for all accounts.", "Blank account", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(dto.LocaleName))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Please select a locale (i.e.: country or region) for all accounts.", "Blank region", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private void persist(AccountsSettings accountsSettings)
|
private void persist(AccountsSettings accountsSettings)
|
||||||
{
|
{
|
||||||
var existingAccounts = accountsSettings.Accounts;
|
var existingAccounts = accountsSettings.Accounts;
|
||||||
@ -152,11 +177,6 @@ namespace LibationWinForms.Dialogs
|
|||||||
// upsert each. validation occurs through Account and AccountsSettings
|
// upsert each. validation occurs through Account and AccountsSettings
|
||||||
foreach (var dto in dtos)
|
foreach (var dto in dtos)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(dto.AccountId))
|
|
||||||
throw new Exception("Please enter an account id for all accounts");
|
|
||||||
if (string.IsNullOrWhiteSpace(dto.LocaleName))
|
|
||||||
throw new Exception("Please select a locale (i.e.: country or region) for all accounts");
|
|
||||||
|
|
||||||
var acct = accountsSettings.Upsert(dto.AccountId, dto.LocaleName);
|
var acct = accountsSettings.Upsert(dto.AccountId, dto.LocaleName);
|
||||||
acct.LibraryScan = dto.LibraryScan;
|
acct.LibraryScan = dto.LibraryScan;
|
||||||
acct.AccountName
|
acct.AccountName
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user