public async Task SaveChangesAsync() { bool _saveOk = true; using (UnitOfWork uow = new UnitOfWork(this.dbFilePath)) { switch (this.AccountType) { case BankAccountType.Checking: if (this.IsNew) { var _resultsAddChecking = await uow.AddCheckingAccountAsync(model as CheckingAccount); _saveOk = _resultsAddChecking.Successful; if (_saveOk) { this.IsDirty = false; this.IsNew = false; this.CanEdit = true; this.CanDelete = true; model = _resultsAddChecking.Results; } else { if (_resultsAddChecking.WorkException != null) { WriteErrorCondition(_resultsAddChecking.WorkException); } else if (!string.IsNullOrEmpty(_resultsAddChecking.Message)) { WriteErrorCondition(_resultsAddChecking.Message); } else { WriteErrorCondition("An unknown error has occurred saving account record"); } } } else { var _resultsUpdateChecking = await uow.UpdateCheckingAccountAsync(model as CheckingAccount); _saveOk = _resultsUpdateChecking.Successful; if (_saveOk) { this.IsDirty = false; this.IsNew = false; this.CanEdit = true; this.CanDelete = true; model = _resultsUpdateChecking.Results; } else { if (_resultsUpdateChecking.WorkException != null) { WriteErrorCondition(_resultsUpdateChecking.WorkException); } else if (!string.IsNullOrEmpty(_resultsUpdateChecking.Message)) { WriteErrorCondition(_resultsUpdateChecking.Message); } else { WriteErrorCondition("An unknown error has occurred saving account record"); } } } break; case BankAccountType.Savings: if (this.IsNew) { var _resultsAddSavings = await uow.AddSavingsAccountAsync(model as SavingsAccount); _saveOk = _resultsAddSavings.Successful; if (_saveOk) { this.IsDirty = false; this.IsNew = false; this.CanEdit = true; this.CanDelete = true; model = _resultsAddSavings.Results; } else { if (_resultsAddSavings.WorkException != null) { WriteErrorCondition(_resultsAddSavings.WorkException); } else if (!string.IsNullOrEmpty(_resultsAddSavings.Message)) { WriteErrorCondition(_resultsAddSavings.Message); } else { WriteErrorCondition("An unknown error has occurred saving account record"); } } } else { var _resultsUpdateSavings = await uow.UpdateSavingsAccountAsync(model as SavingsAccount); _saveOk = _resultsUpdateSavings.Successful; if (_saveOk) { this.IsDirty = false; this.IsNew = false; this.CanEdit = true; this.CanDelete = true; model = _resultsUpdateSavings.Results; } else { if (_resultsUpdateSavings.WorkException != null) { WriteErrorCondition(_resultsUpdateSavings.WorkException); } else if (!string.IsNullOrEmpty(_resultsUpdateSavings.Message)) { WriteErrorCondition(_resultsUpdateSavings.Message); } else { WriteErrorCondition("An unknown error has occurred saving account record"); } } } break; } if (_saveOk) { foreach (var item in this.AccountRegister) { if (item.IsDirty) { switch (item.ItemType) { case AccountRegisterItemViewModel.AccountItemType.Deposits: await(item as DepositViewModel).SaveChangesAsync(); break; case AccountRegisterItemViewModel.AccountItemType.Withdrawals: await(item as WithdrawalViewModel).SaveChangesAsync(); break; } } } } } }