コード例 #1
0
        public async Task <BudgetItemViewModel> AddBudgetItemAsync()
        {
            BudgetItemViewModel vm = new BudgetItemViewModel(this.dbFilePath);

            vm.ItemUpdated += OnItemUpdate;
            BudgetItem item = null;

            if (this.CategoryType == BudgetCategoryType.Income)
            {
                item          = new IncomeItem();
                item.ItemType = BudgetItemType.Income;
            }
            else
            {
                item          = new ExpenseItem();
                item.ItemType = BudgetItemType.Expense;
            }
            item.budgetCategory   = model;
            item.budgetCategoryId = model.id;
            item.StartDate        = DateTime.Now;
            item.recurring        = true;
            item.frequency        = Frequency.Monthly;
            await vm.PopulateVMAsync(item);

            vm.IsNew = true;
            this.BudgetItems.Add(vm);
            this.SelectedBudgetItem = vm;
            return(vm);
        }
コード例 #2
0
        async Task LoadIncomeItemsAsync(int categoryId)
        {
            using (UnitOfWork uow = new UnitOfWork(this.dbFilePath))
            {
                var _resultsCategory = await uow.GetBudgetCategoryAsync(categoryId);

                if (_resultsCategory.Successful)
                {
                    BudgetCategory category            = _resultsCategory.Results;
                    var            _resultsIncomeItems = await uow.GetCategoryIncomeItemsAsync(category);

                    if (_resultsIncomeItems.Successful)
                    {
                        foreach (var item in _resultsIncomeItems.Results)
                        {
                            item.budgetCategory = category;
                            item.ItemType       = BudgetItemType.Income;
                            this.BudgetItems.Add(item);
                            var vm = new BudgetItemViewModel(this.dbFilePath);
                            await vm.PopulateVMAsync(item);

                            this.BudgetItemVMs.Add(vm);
                        }
                    }
                    else
                    {
                        if (_resultsIncomeItems.WorkException != null)
                        {
                            WriteErrorCondition(_resultsIncomeItems.WorkException);
                        }
                        else if (!string.IsNullOrEmpty(_resultsIncomeItems.Message))
                        {
                            WriteErrorCondition(_resultsIncomeItems.Message);
                        }
                        else
                        {
                            WriteErrorCondition("An unknown error has occurred");
                        }
                    }
                }
                else
                {
                    if (_resultsCategory.WorkException != null)
                    {
                        WriteErrorCondition(_resultsCategory.WorkException);
                    }
                    else if (!string.IsNullOrEmpty(_resultsCategory.Message))
                    {
                        WriteErrorCondition(_resultsCategory.Message);
                    }
                    else
                    {
                        WriteErrorCondition("An unknown error has occurred");
                    }
                }
            }
        }
コード例 #3
0
        public async Task <bool> DelteBudgetItemAsync(BudgetItemViewModel vm)
        {
            bool deleted  = false;
            var  itemList = new List <BudgetItemViewModel>();

            if (vm.CanDelete && this.BudgetItems.Contains(vm, new BudgetItemViewModelComparer()))
            {
                deleted = await vm.DeleteAsync();

                if (deleted)
                {
                    this.BudgetItems.Remove(vm);
                }
            }
            else
            {
                this.WriteErrorCondition("Unable to locate provided item in the source collection");
            }

            return(deleted);
        }
コード例 #4
0
        internal async Task PopulateVMAsync(BudgetCategory category)
        {
            model = category;

            using (UnitOfWork uow = new UnitOfWork(dbFilePath))
            {
                switch (category.categoryType)
                {
                case BudgetCategoryType.Expense:
                    var _resultsExpenseItems = await uow.GetCategoryExpenseItemsAsync(category);

                    if (_resultsExpenseItems.Successful)
                    {
                        foreach (var item in _resultsExpenseItems.Results.OrderByDescending(x => x.BudgetedAmount))
                        {
                            item.ItemType         = BudgetItemType.Expense;
                            item.budgetCategory   = category;
                            item.budgetCategoryId = category.id;
                            var vm = new BudgetItemViewModel(this.dbFilePath);
                            await vm.PopulateVMAsync(item);

                            vm.ItemUpdated += OnItemUpdate;
                            vm.IsNew        = false;
                            vm.CanEdit      = true;
                            vm.CanDelete    = true;
                            this.BudgetItems.Add(vm);
                        }
                    }
                    else
                    {
                        if (_resultsExpenseItems.WorkException != null)
                        {
                            WriteErrorCondition(_resultsExpenseItems.WorkException);
                        }
                        else if (!string.IsNullOrEmpty(_resultsExpenseItems.Message))
                        {
                            WriteErrorCondition(_resultsExpenseItems.Message);
                        }
                        else
                        {
                            WriteErrorCondition("An unknown error has occurred loading Expense Items");
                        }
                    }
                    break;

                case BudgetCategoryType.Income:
                    var _resultsIncomeItems = await uow.GetCategoryIncomeItemsAsync(category);

                    if (_resultsIncomeItems.Successful)
                    {
                        foreach (var item in _resultsIncomeItems.Results.OrderByDescending(i => i.BudgetedAmount))
                        {
                            item.ItemType         = BudgetItemType.Income;
                            item.budgetCategory   = category;
                            item.budgetCategoryId = category.id;
                            var vm = new BudgetItemViewModel(this.dbFilePath);
                            await vm.PopulateVMAsync(item);

                            vm.ItemUpdated += OnItemUpdate;
                            vm.IsNew        = false;
                            vm.CanEdit      = true;
                            vm.CanDelete    = true;
                            this.BudgetItems.Add(vm);
                        }
                    }
                    else
                    {
                        if (_resultsIncomeItems.WorkException != null)
                        {
                            WriteErrorCondition(_resultsIncomeItems.WorkException);
                        }
                        else if (!string.IsNullOrEmpty(_resultsIncomeItems.Message))
                        {
                            WriteErrorCondition(_resultsIncomeItems.Message);
                        }
                        else
                        {
                            WriteErrorCondition("An unknown error has occurred loading Income Items");
                        }
                    }
                    break;
                }
            }
        }