Beispiel #1
0
        public ExpenseViewModel(ExtendedExpense extexpense)
        {
            var expense = extexpense.Expense;

            expenseRep   = new ExpenseRepository();
            catRep       = new CategoryRepository();
            CategoryList = new ObservableCollection <Category>();

            var iList = catRep.GetCategoriesAsync();

            foreach (Category i in iList.Result)
            {
                CategoryList.Add(i);
            }
            var Id = expense.ID;

            TheDate        = expense.Date;
            TheTime        = expense.Date.TimeOfDay;
            TheCategory    = extexpense.Category;
            TheDescription = expense.Description;
            TheValue       = Convert.ToString(expense.Value);
            CategoryId     = expense.CategoryId - 1;

            SaveExpenseCommand = new Command(async() =>
            {
                TheDate             = TheDate.Date;
                TheDate            += TheTime;
                expense.ID          = Id;
                expense.Description = TheDescription;
                expense.Value       = Convert.ToDouble(TheValue);
                expense.Date        = TheDate;
                expense.CategoryId  = CategoryId + 1;
                await expenseRep.SaveExpenseAsync(expense);
                TheDescription = string.Empty;
                TheValue       = string.Empty;
                CategoryId     = -1;
            });

            RemoveExpense = new Command(async() =>
            {
                await expenseRep.DeleteExpenseAsync(expense);
            });
        }