public async Task <SavingsWithdrawal> AddSavingsWithdrawalAsync(SavingsWithdrawal withdrawal)
        {
            var inserted = await connection.InsertAsync(withdrawal);

            //withdrawal.IsNew = false;
            return(withdrawal);
        }
        public async Task <SavingsWithdrawal> AddSavingsWithdrawalAsync(SavingsWithdrawal withdrawal)
        {
            if (!context.SavingsWithdrawal.Any(w => w.id == withdrawal.id))
            {
                await Task.Run(() => context.SavingsWithdrawal.Add(withdrawal));

                await Task.Run(() => context.Entry(withdrawal.savingsAccount).State = Microsoft.EntityFrameworkCore.EntityState.Modified);
            }
            else
            {
                throw new Exception("A withdrawal record already exists with the same Primary Key value");
            }
            return(withdrawal);
        }
        public async Task UpdateSavingsWithdrawalAsync(SavingsWithdrawal withdrawal)
        {
            if (context.SavingsWithdrawal.Any(c => c.id == withdrawal.id))
            {
                await Task.Run(() => context.SavingsWithdrawal.Attach(withdrawal));

                await Task.Run(() => context.Entry(withdrawal).State = Microsoft.EntityFrameworkCore.EntityState.Modified);

                if (withdrawal.savingsAccount != null)
                {
                    await Task.Run(() => context.Entry(withdrawal.savingsAccount).State = Microsoft.EntityFrameworkCore.EntityState.Modified);
                }
            }
            else
            {
                throw new Exception("Unable to locate existing Savings Withdrawal record with provided Primary Key value");
            }
        }
        async Task <SavingsWithdrawalViewModel> AddSavingsWithdrawalAsync()
        {
            SavingsWithdrawalViewModel vm = new SavingsWithdrawalViewModel(this.dbFilePath);

            vm.IsNew     = true;
            vm.CanEdit   = true;
            vm.CanDelete = false;
            vm.ItemType  = AccountRegisterItemViewModel.AccountItemType.Withdrawals;

            SavingsWithdrawal withdrawal = new SavingsWithdrawal();

            withdrawal.savingsAccount   = model as SavingsAccount;
            withdrawal.savingsAccountId = model.id;
            withdrawal.transactionDate  = DateTime.Now;
            await vm.PopulateVMAsync(withdrawal);

            //this.AccountRegister.Add(vm);
            //await GroupAccountItemsAsync();
            //this.SelectedRegisterItem = vm;

            return(vm);
        }
        public async Task PopulateVMAsync(SavingsWithdrawal withdrawal)
        {
            this.model             = withdrawal;
            this.accountModel      = withdrawal.savingsAccount;
            this.ItemId            = this.model.id;
            this.ItemType          = AccountItemType.Withdrawals;
            this.ItemAmount        = model.transactionAmount;
            this.EndingBalance     = model.endingBalance;
            this.ItemDescription   = model.description;
            this.Description       = this.model.description;
            this.TransactionDate   = model.transactionDate;
            this.ItemDate          = model.transactionDate;
            this.TransactionAmount = model.transactionAmount;
            this.ObjectColorCode   = this.model.ColorCode;

            this.BudgetItemId = model.budgetExpenseId;

            //await this.LoadBudgetData();

            //using (UnitOfWork uow = new UnitOfWork(this.dbFilePath))
            //{
            //    var _results = await uow.GetAllBudgetCategoriesAsync();
            //    if (_results.Successful)
            //    {
            //        foreach (BudgetCategory category in _results.Results)
            //        {
            //            var _resultsItemCountCheck = await uow.GetCategoryExpenseItemsAsync(category);
            //            if (_resultsItemCountCheck.Successful && _resultsItemCountCheck.Results.Count > 0)
            //            {
            //                if (category.categoryType == Models.BudgetCategoryType.Expense)
            //                {
            //                    this.BudgetCategories.Add(category);
            //                    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(CategorySelectEnabled)));
            //                }
            //            }
            //        }

            //        if (this.BudgetItemId > 0)
            //        {
            //            var _resultsGetBudgetItem = await uow.GetExpenseItemAsync(this.BudgetItemId);
            //            if (_resultsGetBudgetItem.Successful)
            //            {
            //                var selectedItem = _resultsGetBudgetItem.Results;
            //                if (this.BudgetCategories.Any(c => c.id == selectedItem.budgetCategoryId))
            //                {
            //                    this.SelectedCategory = this.BudgetCategories.FirstOrDefault(c => c.id == selectedItem.budgetCategoryId);
            //                    this.SelectedBudgetItem = selectedItem;
            //                }
            //            }
            //            else
            //            {
            //                if (_resultsGetBudgetItem.WorkException != null)
            //                {
            //                    WriteErrorCondition(_resultsGetBudgetItem.WorkException);
            //                }
            //                else if (!string.IsNullOrEmpty(_resultsGetBudgetItem.Message))
            //                {
            //                    WriteErrorCondition(_resultsGetBudgetItem.Message);
            //                }
            //                else
            //                {
            //                    WriteErrorCondition("An unknown error has occurred populating withdrawal record");
            //                }
            //            }
            //        }

            //    }
            //    else
            //    {
            //        if (_results.WorkException != null)
            //        {
            //            WriteErrorCondition(_results.WorkException);
            //        }
            //        else if (!string.IsNullOrEmpty(_results.Message))
            //        {
            //            WriteErrorCondition(_results.Message);
            //        }
            //        else
            //        {
            //            WriteErrorCondition("An unknown error has occurred getting category records");
            //        }
            //    }
            //}
        }
 public async Task DeleteSavingsWithdrawalAsync(SavingsWithdrawal withdrawal)
 {
     var deleted = await connection.DeleteAsync(withdrawal);
 }
 public async Task UpdateSavingsWithdrawalAsync(SavingsWithdrawal withdrawal)
 {
     var updated = await connection.UpdateAsync(withdrawal);
 }
 public void Put(int id, [FromBody] SavingsWithdrawal item)
 {
     throw new NotImplementedException();
 }