async void OnAddExpense(object sender, EventArgs e)
        {
            decimal expense  = 0;
            var     canParse = decimal.TryParse(TxtExpense.Text, out expense);

            if (CmbCategory.SelectedIndex == -1)
            {
                await DisplayAlert("Pequeño problema", "Debe elegir una categoría", "Ok");

                return;
            }

            if (!canParse)
            {
                await DisplayAlert("Pequeño problema", "El número ingresado como gasto no es valido", "Ok");

                return;
            }
            var selectedCategoryName = CmbCategory.Items[CmbCategory.SelectedIndex];
            var category             = Category.GetDefaultCategories().First(c => c.Name == selectedCategoryName);

            var expenseObject = new Expense
            {
                CategoryId = category.Id,
                Value      = expense
            };


            var expenseRepository = new ExpenseRepository();

            expenseRepository.AddItem(expenseObject);
            await Navigation.PopAsync();
        }
        public void OnDelete(object sender, EventArgs e)
        {
            var mi   = ((MenuItem)sender);
            var item = mi.CommandParameter;
            var expenseRepository = new ExpenseRepository();

            expenseRepository.DeleteItem(((Expense)item).Id);
            LoadList();
        }
        protected override void OnAppearing()
        {
            base.OnAppearing();

            var expenseRepository = new ExpenseRepository();
            var expenses          = expenseRepository.GetExpenses();

            this.ViewModel.TotalExpenseCount = expenses.Sum(e => e.Value);
        }
        private void LoadList()
        {
            var expenseRepository = new ExpenseRepository();
            var expenses          = expenseRepository.GetExpenses();

            ViewModel.Expenses.Clear();
            var categories = Category.GetDefaultCategories();

            foreach (var exp in expenses)
            {
                exp.Category = categories.FirstOrDefault(cat => cat.Id == exp.CategoryId);
                ViewModel.Expenses.Add(exp);
            }
        }