public TransferBundle GetTransferBundle(String apbnKey, String regionId) { if (KawalDesaController.GetCurrentUser() == null &®ionId == "0") return GetInScopeTransferBundle(apbnKey); var region = GetRegion(regionId); var result = new TransferBundle { Region = region }; if(region.Type < RegionType.DESA) { result.TransferRecapitulations = db.TransferRecapitulations .Where(r => r.ApbnKey == apbnKey && (r.RegionId == regionId || r.ParentRegionId == regionId)) .ToList(); } else { string syear = apbnKey; if (apbnKey.Length > 4) syear = apbnKey.Substring(0, 4); int year = Convert.ToInt32(syear); result.Transfers = db.Transfers .Where(e => e.Year == year && e.IsActivated && e.fkRegionId == regionId) .ToList(); } result.TransferProgress = db.TransferProgresses .Where(r => r.fkRegionId == regionId && r.ApbnKey == apbnKey) .ToList(); return result; }
public TransferBundle GetInScopeTransferBundle(string apbnKey) { var region = GetRegion("0"); var result = new TransferBundle { Region = region, }; var scopedRegionIds = db.Regions.Where(r => r.IsInScope).Select(r => r.Id).ToList(); result.TransferRecapitulations = db.TransferRecapitulations .Where(r => r.ApbnKey == apbnKey && (scopedRegionIds.Contains(r.RegionId))) .ToList(); var total = new TransferRecapitulation { ApbnKey = apbnKey, RegionId = "0", RegionName = region.Name }; foreach(var recap in result.TransferRecapitulations) { total.BudgetedDd += recap.BudgetedDd; total.BudgetedAdd += recap.BudgetedAdd; total.BudgetedBhpr += recap.BudgetedBhpr; } result.TransferRecapitulations.Add(total); result.TransferProgress = db.TransferProgresses .Where(r => r.ApbnKey == apbnKey && (scopedRegionIds.Contains(r.fkRegionId))) .ToList(); result.TransferRecapitulations.Add(total); return result; }