예제 #1
0
        private BudgetPlanItemVM FindBudgetPlanItemVMFor(BudgetPlan budgetPlan)
        {
            Diagnostics.Start();
            var budgetPlanItem = AllBudgetPlanList
                                 .Where(x => x.CashFlow.Id == budgetPlan.CashFlowId && x.Budget.Id == budgetPlan.BudgetId)
                                 .First();

            Diagnostics.Stop();
            return(budgetPlanItem);
        }
예제 #2
0
        private void LoadBudgetPlanItems()
        {
            Diagnostics.Start();
            var cashFlows = CachedService.GetAllCashFlows();

            var sql = PetaPoco.Sql.Builder
                      .Select("*")
                      .From("BudgetPlan")
                      .InnerJoin("Budget")
                      .On("Budget.Id = BudgetPlan.BudgetId")
                      .InnerJoin("CashFlow")
                      .On("CashFlow.Id = BudgetPlan.CashFlowId")
                      .InnerJoin("CashFlowGroup")
                      .On("CashFlow.CashFlowGroupId = CashFlowGroup.Id")
                      .Where("BudgetPlan.BudgetId = @0", Budget.Id);
            var budgetPlans = Database.Query <BudgetPlan, Budget, CashFlow, CashFlowGroup>(sql).ToList();

            Budget.BudgetPlanItems.Clear();
            ((BindableCollectionExt <BudgetPlan>)Budget.BudgetPlanItems).AddRange(budgetPlans);

            DetachFromBudgetPlanItems();
            AllBudgetPlanList.Clear();
            foreach (var cashFlow in cashFlows)
            {
                var planItems = budgetPlans.Where(x => x.CashFlow.Id == cashFlow.Id).ToList();
                AllBudgetPlanList.Add(new BudgetPlanItemVM(Budget, cashFlow, planItems));
            }

            BudgetPlanListGrouped.Clear();
            cashFlows.GroupBy(x => x.GroupName).ForEach(cf =>
            {
                var groupBudgetPlanItems = AllBudgetPlanList.Where(x => x.GroupName == cf.Key).ToList();
                var groupedItem          = new BudgetPlanGroupItemVM(groupBudgetPlanItems)
                {
                    GroupName = cf.Key,
                };
                BudgetPlanListGrouped.Add(groupedItem);
            });

            AttachToBudgetPlanItems();
            Diagnostics.Stop();
        }