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(); }
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(); }